interesting fact about StrCaseCmp

Martin Pool mbp at samba.org
Wed Feb 19 00:36:25 GMT 2003


On 18 Feb 2003, Ludolf Holzheid <lholzheid at bihl-wiedemann.de> wrote:

> In the embedded/real time world, malloc() and friends are strongly
> deprecated as you can't predict how long they will take.  They have
> to go through a linked list of unknown length and may even start a
> garbage collection.

Well that's fine, but Samba is obviously not a hard real time program,
so it's hardly relevant.  Bear in mind that it generally runs in
virtual memory and so *any* memory access can take an unboundedly long
time.

> If StrCaseCmp() is really that sensitive w.r.t. processor cycles, you 
> better keep the malloc()ed buffers between the calls and increase 
> their size (by calling free() and malloc(), not realloc()) if the 
> strings to be compared do not fit.

With all due respect, this is a really silly argument.  Are you not
familiar with the saying that premature optimization is the root of
all evil?  And anyhow, if it doesn't need to be correct, it can be as
fast as you like.  It can just return true...

If this function needs to be fast, then it should not be *copying* the
strings *four* times to compare them, when comparing the first *byte*
would often be enough.  

A minimal change to make StrCaseCmp at least not truncate strings
would involve adding a malloc(), which is harmless since it's very
slow already.  A good implementation of StrCaseCmp shouldn't do any
copying or allocation.  When I get a chance I'll write that and post
numbers.

-- 
Martin 


More information about the samba-technical mailing list