From: Charlie G. <cha...@gm...> - 2007-10-16 16:58:03
|
On 10/16/07, Frank Wierzbicki <fwi...@gm...> wrote: > On 10/16/07, Brian Zhou <b8...@gm...> wrote: > > The only change I need to make is: > > Index: src/org/python/core/PyString.java > > =================================================================== > > --- src/org/python/core/PyString.java (revision 3607) > > +++ src/org/python/core/PyString.java (working copy) > > @@ -2027,10 +2027,7 @@ > > * the low-order bits of its corresponding char. > > */ > > public static byte[] to_bytes(String s) { > > - int len = s.length(); > > - byte[] b = new byte[len]; > > - s.getBytes(0, len, b, 0); > > - return b; > > + return s.getBytes(); > > } > The only trouble here is that getBytes() uses the default char set for > the platform -- unlike the deprecated method we are currently using > which uses "raw" bytes -- with a little work we could probably use the > getBytes() method that takes an encoding -- anybody know how that > could be done effectively? I know there has been some encoding work > lately. Yeah, replacing calls to getBytes() with to_bytes was the majority of the encoding work that happened. I'm just going to replace the call to the deprecated getBytes with the following: byte[] b = new byte[s.length()]; for(int i = 0; i < b.length; i++) { b[i] = (byte)s.charAt(i); } return b; It's the same thing getBytes is doing internally, only a little slower because it has to go through charAt instead of accessing the char array directly. Charlie |