Re: [PHP4BETA] cvs: php4 /ext/standard/ levenshtein.c

[email protected] (Zeev Suraski)
Newsgroups php.version4
Message-ID <[email protected]>
The problem with the 'dirty trick' is that sizeof(void *) isn't necessarily 
equal to sizeof(int).  On many platforms it isn't.

Zeev

At 22:07 23/05/2000 , Hartmut Holzgraefe wrote:
>hholzgra                Tue May 23 22:07:32 2000 EDT
>
>   Modified files:
>     /php4/ext/standard  levenshtein.c
>   Log:
>   a little less optimized, but no dirty tricks anymore
>
>
>Index: php4/ext/standard/levenshtein.c
>diff -u php4/ext/standard/levenshtein.c:1.4 
>php4/ext/standard/levenshtein.c:1.5
>--- php4/ext/standard/levenshtein.c:1.4 Tue May 23 21:27:02 2000
>+++ php4/ext/standard/levenshtein.c     Tue May 23 22:07:32 2000
>@@ -15,7 +15,7 @@
>     | Author: Bjørn Borud - Guardian Networks AS <[email protected]>       |
>     +----------------------------------------------------------------------+
>   */
>-/* $Id: levenshtein.c,v 1.4 2000/05/23 19:27:02 sas Exp $ */
>+/* $Id: levenshtein.c,v 1.5 2000/05/23 20:07:32 hholzgra Exp $ */
>
>  #include "php.h"
>  #include <stdlib.h>
>@@ -25,10 +25,11 @@
>
>  static int calc_levdist(const char *s1, const char *s2) /* faster, but 
> obfuscated */
>  {
>-       register char *p1,*p2;
>+       register char *p1,*p2;
>         register int i,j,n;
>         int l1=0,l2=0;
>         char r[512];
>+       const char *tmp;
>
>         /* skip equal start sequence, if any */
>         while(*s1==*s2) {
>@@ -54,22 +55,15 @@
>         /* reset pointers, adjust length */
>         s1-=l1++;
>         s2-=l2++;
>+
>
>         /* possible dist to great? */
>         if(abs(l1-l2)>=255) return -1;
>
>         /* swap if l2 longer than l1 */
>         if(l1<l2) {
>-               const char *s3;
>-               int l3;
>-
>-               s3 = s1;
>-               s1 = s2;
>-               s2 = s3;
>-
>-               l3 = l1;
>-               l1 = l2;
>-               l2 = l3;
>+               tmp=s1; s1=s2; s2=tmp;
>+               l1 ^= l2; l2 ^= l1; l1 ^= l2;
>         }
>
>
>
>
>
>--
>PHP 4.0 Beta Mailing List <http://www.php.net/version4/>
>To unsubscribe, e-mail: [email protected]
>For additional commands, e-mail: [email protected]
>To contact the list administrators, e-mail: [email protected]

--
Zeev Suraski   <[email protected]>  http://www.zend.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.