From: Rick DeNatale Date: 2011-02-26T06:27:39+09:00 Subject: [ruby-core:35380] Re: [Ruby 1.9 - Feature #4447] [Open] add String#byteslice() method On Fri, Feb 25, 2011 at 3:42 PM, Gary Wright wrote: > > On Feb 25, 2011, at 4:52 AM, Martin J. D�rst wrote: > >> string.force_encoding(ENCODING::BINARY).slice almost does what you want, very efficiently. The problem is that the string will then be marked as BINARY. This can be set back, but it may affect operations that run in parallel. To expand on this, something like > > Isn't any manipulation of a string via two threads simultaneously already not thread safe? > > That is to say, toggling the encoding doesn't make the situation any worse than it is with String#slice all by itself. No, the issue is that String#force_encoding mutates the string, but String#slice does not. str = "Hello World" => "Hello World" > str.slice(4,4) => "o Wo" > str => "Hello World" -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale