From: Nicolas C. <war...@fr...> - 2003-06-23 08:56:51
|
> > let add_uchar buf u = > > let masq = 0b111111 in > > let k = int_of_uchar u in > > if k < 0 || k >= 0x4000000 then begin > > Buffer.add_char buf (Char.chr (0xfc + (k lsr 30))); > > Buffer.add_char buf (Char.unsafe_chr (0x80 lor ((k lsr 24) land masq))); > > You might try replacing 'masq' with the actual literal value, > though the compiler should be able to determine its a constant, > it may not. I'm pretty sure it is doing it. Since masq is non-mutable, this is an easy optimisation for the compiler. BTW, you can check the native output code by running ocamlopt with -S > The other thing to do here is reorder the tests: > test k>=0 && k<=07f first, then k<=07ff ..., reason being > that the first case is 99.99% of cases. The second > is 99.99% of the rest of cases. This one the compiler can't :-) Nicolas Cannasse |