From: Nicolas C. <war...@fr...> - 2004-04-09 20:57:03
|
> On Fri, 9 Apr 2004, Nicolas Cannasse wrote: > > A couple of questions: > > > external unsafe_char_of_int : int -> char = "%identity" > > Is this really any faster than using the pervasives char_of_int? %identity means it's removed at compile time, it's just a typed Obj.magic. on the other side you have : let char_of_int n = if n < 0 || n > 255 then invalid_arg "char_of_int" else unsafe_char_of_int n > > let inv_chars = > > let a = Array.make 256 (-1) in > > for i = 0 to 63 do > > Array.unsafe_set a (int_of_char (Array.unsafe_get chars i)) i; > > Likewise- especially since this code will be executed only once (on module > load), is unsafe_set worthwhile to call? > > > let c = int_of_char (String.unsafe_get s i) in > > Ditto & etc. It's always better to use unsafe when you're really sure that it will never breaks. IMHO, basic functions such as b64 encode/decode should be tuned to get best performances. As long as using unsafe_get instead of get does not break code readability... it's worth doing. Regards, Nicolas Cannasse |