Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Again on pattern matching and strings
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Sven Luther <luther@d...>
Subject: Re: [Caml-list] Again on pattern matching and strings
On Thu, Oct 24, 2002 at 03:24:26PM +0200, Luc Maranget wrote:
> > 
> > 
> > 
> > Jacques Garrigue wrote:
> > 
> > > That message was about polymorphic variants, which are encoded as
> > > integers, and for which pattern-matching is a decision tree.
> > > 
> > > However, if you look in bytecomp/matching.ml, you will see that string
> > > patterns are just checked sequentially (the ordering is not used).
> > > Moreover, the match compiler seems to be clever enough to compile
> > > properly the above style:...
> > 
> > Very strange. I thought the Ocaml compiler sould 
> > precalculate the branch of pattern matching to be taken, and 
> > then jump, thereby avoiding sequential checking. I'm sorry 
> > for my mistake.
> 
> If you are interested in pm code, I would suggest that you have a look
> at the produced code after pattern-matching compilation (option -dlambda),
> before looking at the compiler sources.
> 
> The issue is not really PM bu rather switches: how to compile
> a serche in a ordered list of constants ?
> 
> 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,

Sven Luther
-------------------
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