summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNuno Lopes <nlopess@php.net>2006-11-10 23:27:11 +0000
committerNuno Lopes <nlopess@php.net>2006-11-10 23:27:11 +0000
commit94404da6063d3bb53bc6519529e40f83a78ae136 (patch)
treea12180c528382d1adc91fc5e5598ac7b8d68bd21
parent88e827f3f1a3225aeb04d2a87f79e39545f9d173 (diff)
downloadphp-git-94404da6063d3bb53bc6519529e40f83a78ae136.tar.gz
fix the bug I introduced previously, sorry
anyway, convert the recursive version of the binary search to an iterative one
-rw-r--r--ext/date/lib/parse_tz.c45
1 files changed, 16 insertions, 29 deletions
diff --git a/ext/date/lib/parse_tz.c b/ext/date/lib/parse_tz.c
index 723017eef0..69551ac666 100644
--- a/ext/date/lib/parse_tz.c
+++ b/ext/date/lib/parse_tz.c
@@ -192,39 +192,26 @@ void timelib_dump_tzinfo(timelib_tzinfo *tz)
}
}
-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;
+
+ 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;
+ }
- if (pos == -1) {
- return 0;
- }
+ } while (left <= right);
- (*tzf) = &(tzdb->data[pos + 20]);
- return 1;
+ return 0;
}
const timelib_tzdb *timelib_builtin_db(void)