diff options
author | Derick Rethans <derick@php.net> | 2005-06-28 17:56:47 +0000 |
---|---|---|
committer | Derick Rethans <derick@php.net> | 2005-06-28 17:56:47 +0000 |
commit | 28e76fe7f488ad79451d25f1cd6b0e50223bd18f (patch) | |
tree | 47cc3ef19a0425d7ec8d3486e44eed20d9a3297c /ext/date/lib/parse_tz.c | |
parent | c06fbbf0c436fcc275e06d4cd517fbbe5374694f (diff) | |
download | php-git-28e76fe7f488ad79451d25f1cd6b0e50223bd18f.tar.gz |
- Implemented binary search for timezone abbreviations and timezone identifier
lookups. (Based on a patch by Nuno Lopes)
Diffstat (limited to 'ext/date/lib/parse_tz.c')
-rw-r--r-- | ext/date/lib/parse_tz.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/ext/date/lib/parse_tz.c b/ext/date/lib/parse_tz.c index 60aac4435d..69bf196393 100644 --- a/ext/date/lib/parse_tz.c +++ b/ext/date/lib/parse_tz.c @@ -185,27 +185,36 @@ void timelib_dump_tzinfo(timelib_tzinfo *tz) } } +static int tz_search(char *timezone, int left, int right) +{ + int mid, cmp; + + if (left > right) { + return -1; /* not found */ + } + + mid = (left + right) / 2; + + cmp = strcmp(timezone, timezonedb_idx[mid].id); + if (cmp < 0) { + return tz_search(timezone, left, mid - 1); + } else if (cmp > 0) { + return tz_search(timezone, mid + 1, right); + } else { /* (cmp == 0) */ + return timezonedb_idx[mid].pos; + } +} + + static int seek_to_tz_position(char **tzf, char *timezone) { - int found; - tzdb_idx *ptr; - - /* Reset Index Position */ - ptr = timezonedb_idx; - - /* Start scanning the index file for the timezone */ - found = 0; - do { - if (strcmp(timezone, ptr->id) == 0) { - found = 1; - (*tzf) = &php_timezone_db_index[ptr->pos + 20]; - break; - } - ptr++; - } while (ptr->id != NULL); - if (!found) { + int pos = tz_search(timezone, 0, sizeof(timezonedb_idx)/sizeof(*timezonedb_idx)-1); + + if (pos == -1) { return 0; } + + (*tzf) = &php_timezone_db_index[pos + 20]; return 1; } |