[Date Prev][Date Next] [Chronological] [Thread] [Top]

RE: struct berval comparison



> -----Original Message-----
> From: owner-openldap-devel@OpenLDAP.org
> [mailto:owner-openldap-devel@OpenLDAP.org]On Behalf Of Pierangelo
> Masarati

> I'd like to avoid any unnecessary str[case]cmp on berval->bv_val,
> so I added three functions, ber_memcmp(), ber_cmp() and ber_casecmp()
> that are meant to replace memcmp, strcmp and strcasecmp respectively
> when bervals are involved.

> However their behavior in my implementation differs from that of the
> replaced functions, because what I basically want to detect is match
> without affecting ordering issues, so their use should be careful.
 
> the match is:
 
> if the lengths differ, return l1-l2; otherwise return the comparison
> on the values.  
 
> 1) is this acceptable, are there comments?
> 2) is the naming OK, any suggestions before I heavily modify the code?

I converted entry_dn_cmp and many other of the AVL sort functions to
behave this way already. It's fine when we want a sorted order but we
don't care that it is lexicographic; it's much faster to compare bv_len
first and avoid strcmp if we can. And obviously it's also fine for a
straight is/is not match.

In general I would not create these functions though; I would define
them as macros that use the standard libc memcmp/strcasecmp if needed,
simply because the libc routines are likely to be well optimized, and
using a macro avoids the function call overhead if the *cmp() is unneeded.

That's my (not so humble }-) opinion...

  -- Howard Chu
  Chief Architect, Symas Corp.       Director, Highland Sun
  http://www.symas.com               http://highlandsun.com/hyc  
  Symas: Premier OpenSource Development and Support