From: Yamagata Y. <yor...@mb...> - 2003-06-23 15:37:44
|
From: "Nicolas Cannasse" <war...@fr...> Subject: Re: [Ocaml-lib-devel] second proposal of UChar, UTF8 modules Date: Mon, 23 Jun 2003 17:55:16 +0900 > 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 It does. > 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. k could be negative. A better way is if k >= 0 then if k <= 0x7f then ... else if k <= 0x7ff then ... else ... if k <= 0x3ffffff then ... else (*) else (*) but then the code (*) is duplicated. I don't think an extra integer comparison is a big deal. More optimization also could be possible by the unsafe operations. For example, iter can use unsafe_next. (which does not check whether i is valid.) let rec iter_aux proc s i = if i >= String.length s then () else let u = look s i in proc u; iter_aux proc s (next s i) But, it makes the code duplicated (unsafe_next and next. If we implement next using unsafe_next, then we add one extra function call for the safe operation1, which is IMO not desirable.) and makes the code more prone to error. (In this case, we implicitly assume inter_aux never be called with i < 0.) My opinion is that uTF8.ml is already optimized well, unless we have a good benchmark. -- Yamagata Yoriyuki |