Re: php & Unicode 5.1 characters
Posted: Thu Apr 02, 2009 11:46 am
You sure that ord( $s[$i] ) is slower than $_byteMap[ $s[$i] ] ? I'd say the latter involves 128 string comparisons on average for every char lookup (since it's using each char from $s as a key in a string-indexed array with 256 elements). I have no clue about how well PHP's ord() function is implemented, but it surely wouldn't make sense to me if it took significantly more time.Chris Corbyn wrote:Yours will be a lot slower for larger strings BTW due to the repeated ord() usage. Some of the verbosity of mine is because it needs to be fast (it's part of Swift Mailer).
Either way, I'd say the whole conversion altogether shouldn't take much time anyway (few seconds tops?) for very long strings (as in, several megabytes) on any random cheap-ass machine.
BTW it might be interesting to see if your method gets faster when you move commonly used characters (0x65 or 'e' is probably the most frequent in common textual data) to the beginning of the $_byteMap array