nlopess         Fri Nov 10 23:27:11 2006 UTC

  Modified files:              (Branch: PHP_5_2)
    /php-src/ext/date/lib       parse_tz.c 
  Log:
  fix the bug I introduced previously, sorry
  anyway, convert the recursive version of the binary search to an iterative one
  
http://cvs.php.net/viewvc.cgi/php-src/ext/date/lib/parse_tz.c?r1=1.20.2.6.2.7&r2=1.20.2.6.2.8&diff_format=u
Index: php-src/ext/date/lib/parse_tz.c
diff -u php-src/ext/date/lib/parse_tz.c:1.20.2.6.2.7 
php-src/ext/date/lib/parse_tz.c:1.20.2.6.2.8
--- php-src/ext/date/lib/parse_tz.c:1.20.2.6.2.7        Fri Nov 10 17:32:15 2006
+++ php-src/ext/date/lib/parse_tz.c     Fri Nov 10 23:27:11 2006
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: parse_tz.c,v 1.20.2.6.2.7 2006/11/10 17:32:15 nlopess Exp $ */
+/* $Id: parse_tz.c,v 1.20.2.6.2.8 2006/11/10 23:27:11 nlopess Exp $ */
 
 #include "timelib.h"
 
@@ -192,39 +192,26 @@
        }
 }
 
-static int tz_search(char *timezone, unsigned int left, unsigned int right, 
const timelib_tzdb *tzdb)
-{
-       int mid, cmp;
-
-       if (left > right) {
-               return -1; /* not found */
-       }
- 
-       mid = (left + right) / 2;
- 
-       cmp = strcasecmp(timezone, tzdb->index[mid].id);
-       if (cmp < 0) {
-               return tz_search(timezone, left, mid - 1, tzdb);
-       } else if (cmp > 0) {
-               return tz_search(timezone, mid + 1, right, tzdb);
-       } else { /* (cmp == 0) */
-               return tzdb->index[mid].pos;
-       }
-}
-
-
 static int seek_to_tz_position(const unsigned char **tzf, char *timezone, 
const timelib_tzdb *tzdb)
 {
-       int     pos;
-       
-       pos = tz_search(timezone, 0, tzdb->index_size - 1, tzdb);
+       int left = 0, right = tzdb->index_size - 1;
 
-       if (pos == -1) {
-               return 0;
-       }
+       do {
+               int mid = ((unsigned)left + right) >> 1;
+               int cmp = strcasecmp(timezone, tzdb->index[mid].id);
+
+               if (cmp < 0) {
+                       right = mid - 1;
+               } else if (cmp > 0) {
+                       left = mid + 1;
+               } else { /* (cmp == 0) */
+                       (*tzf) = &(tzdb->data[tzdb->index[mid].pos + 20]);
+                       return 1;
+               }
+
+       } while (left <= right);
 
-       (*tzf) = &(tzdb->data[pos + 20]);
-       return 1;
+       return 0;
 }
 
 const timelib_tzdb *timelib_builtin_db(void)

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to