You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by peter royal <pe...@pobox.com> on 2006/03/11 17:12:58 UTC

Re: svn commit: r385098 - in /directory/trunks/mina/core/src: main/java/org/apache/mina/common/ByteBuffer.java test/java/org/apache/mina/common/ByteBufferTest.java

On Mar 11, 2006, at 11:00 AM, trustin@apache.org wrote:
> ** Applied Peter's patch to ByteBuffer after some optimization.

I don't like this optimization.. seems premature.

In my original patch, I first had it trying to auto-expand based on  
average bytes per character, then max bytes per character, and then  
giving up.. (and then, only calculating expected length if it was  
really needed, which could be argued is an optimization..)

In the tweak you committed, it is still possible for it to go into an  
infinite loop if we missed a case, and I feel far more comfortable  
knowing that the algorithm might be a tad slower and never have the  
possibility of going into an infinite loop.

The core of my concern is that the expectedLength is only based on  
the average bytes per character, which for UTF-8 is only 1.1. The max  
is 4, so its not that hard for the expected length to be way off if  
you have many wide characters.
-pete


-- 
(peter.royal|osi)@pobox.com - http://fotap.org/~osi


Re: svn commit: r385098 - in /directory/trunks/mina/core/src: main/java/org/apache/mina/common/ByteBuffer.java test/java/org/apache/mina/common/ByteBufferTest.java

Posted by peter royal <pr...@apache.org>.
On Mar 11, 2006, at 11:23 AM, Trustin Lee wrote:
> Yep I noticed it by myself and fixed it again:
>
> http://svn.apache.org/viewcvs?rev=385102&view=rev

excellent, ty :)

> The core of my concern is that the expectedLength is only based on
>> the average bytes per character, which for UTF-8 is only 1.1. The max
>> is 4, so its not that hard for the expected length to be way off if
>> you have many wide characters.
>
>
> I thought the max is 6.  It seems like there's a wrong documentation:
>
> http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
>
> The official site claims that it takes up to four octets:
>
> http://www.utf-8.com/

Odd, I was just going by what the UTF-8 encoder said was its maximum,  
figuring that it wouldn't lie about what it was going to do :)
-pete

-- 
proyal@apache.org - http://fotap.org/~osi



Re: svn commit: r385098 - in /directory/trunks/mina/core/src: main/java/org/apache/mina/common/ByteBuffer.java test/java/org/apache/mina/common/ByteBufferTest.java

Posted by Trustin Lee <tr...@gmail.com>.
On 3/12/06, peter royal <pe...@pobox.com> wrote:
>
> On Mar 11, 2006, at 11:00 AM, trustin@apache.org wrote:
> > ** Applied Peter's patch to ByteBuffer after some optimization.
>
> I don't like this optimization.. seems premature.


Yep I noticed it by myself and fixed it again:

http://svn.apache.org/viewcvs?rev=385102&view=rev

Trustin

The core of my concern is that the expectedLength is only based on
> the average bytes per character, which for UTF-8 is only 1.1. The max
> is 4, so its not that hard for the expected length to be way off if
> you have many wide characters.


I thought the max is 6.  It seems like there's a wrong documentation:

http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8

The official site claims that it takes up to four octets:

http://www.utf-8.com/

Thanks,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6