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

From: Date: Tue, 23 May 2000 22:16:07 +0000
Subject: Re: [PHP4BETA] cvs: php4 /ext/standard/ levenshtein.c
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-15602@lists.php.net to get a copy of this message
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 <borud@guardian.no>       |
    +----------------------------------------------------------------------+
*/ -/* $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: php4beta-unsubscribe@lists.php.net For additional commands, e-mail: php4beta-help@lists.php.net To contact the list administrators, e-mail: php4beta-admin@lists.php.net
-- Zeev Suraski <zeev@zend.com> http://www.zend.com/

« previous php.version4 (#15602) next »