Browse thread
Re: [Caml-list] Again on pattern matching and strings
- Luc Maranget
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Luc Maranget <luc.maranget@i...> |
| Subject: | Re: [Caml-list] Again on pattern matching and strings |
> > To sum it up for strings : strings are atoms to the PM compiler which > > never look into them, it only compares one string against another, for > > equality only. The match compiler does not make avantage of the known > > pattern string in any sense. The match compiler does not make > > avantage of the existence of a lexical ordering on strings. In fact > > many << optimizations >> are posible here, none is performed. > > So, i suppose replacing all strings in a pattern matching by an integer > pointing to hashtable or something would improve performance a lot if > the same string is pattern matched over and over again ? > > Friendly, Indeed, but there are other possibilities, such as tries. In the style match x with | "a" -> 1 | "ab" -> 2 | "abc" -> 3 | _ -> 4 ===> switch get_char 0 x with | 'a' -> begin switch get_char 1 x with | eos -> 1 (* end of string ... *) | 'b' -> (switch get_char 2 x with ...) | _ -> 4 end | _ -> 4 Where switch operates on machine integers. > > Sven Luther > --Luc ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners