From: Marcus Boerger Date: Sat, 22 Feb 2003 23:47:09 +0000 (+0000) Subject: Dropped optimization X-Git-Tag: RELEASE_0_5~818 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fbe7e1d977307ef22b9c7c2c8854365cc4e9b6b4;p=php Dropped optimization # It is impossible to combine skip=-1 searches with firstkey/nextkey results --- diff --git a/ext/dba/libinifile/inifile.c b/ext/dba/libinifile/inifile.c index b53128760e..406798302e 100644 --- a/ext/dba/libinifile/inifile.c +++ b/ext/dba/libinifile/inifile.c @@ -254,40 +254,12 @@ val_type inifile_fetch(inifile *dba, const key_type *key, int skip TSRMLS_DC) { val_type val; int res, grp_eq = 0; - if (skip == -1) { - if (dba->next.key.group && dba->next.key.name && !inifile_key_cmp(&dba->next.key, key TSRMLS_CC)) { - /* we got it already from last fetch */ - val.value = estrdup(dba->next.val.value ? dba->next.val.value : ""); - /* allow faster access by automatically getting next key */ - php_stream_seek(dba->fp, dba->next.pos, SEEK_SET); - ln.key.group = estrdup(dba->next.key.group ? dba->next.key.group : ""); - inifile_read(dba, &ln TSRMLS_CC); - inifile_line_free(&dba->next); - dba->next = ln; - return val; - } else if (dba->curr.key.group && dba->curr.key.name && !inifile_key_cmp(&dba->curr.key, key TSRMLS_CC)) { - /* we got it already from firstkey/lastkey */ - /* - * this optimisation does not work when firstkey/nextkey found - * any instance other than the one instance wanted. - */ - val.value = estrdup(dba->curr.val.value ? dba->curr.val.value : ""); - /* allow faster access by automatically getting next key - * we must use the line pointer 'next' since we cannot change the - * line pointer of firstkey/nextkey - */ - php_stream_seek(dba->fp, dba->curr.pos, SEEK_SET); - ln.key.group = estrdup(dba->curr.key.group ? dba->curr.key.group : ""); - inifile_read(dba, &ln TSRMLS_CC); - inifile_line_free(&dba->next); - dba->next = ln; - return val; - } - } - - /* the slow way: restart and seacrch */ - if (skip != -1 || !dba->next.key.group || !dba->next.key.name || inifile_key_cmp(&dba->next.key, key TSRMLS_CC)) { + if (skip == -1 && dba->next.key.group && dba->next.key.name && !inifile_key_cmp(&dba->next.key, key TSRMLS_CC)) { + /* we got position already from last fetch */ + php_stream_seek(dba->fp, dba->next.pos, SEEK_SET); + } else { /* specific instance or not same key -> restart search */ + /* the slow way: restart and seacrch */ php_stream_rewind(dba->fp); } inifile_line_free(&dba->next); @@ -298,10 +270,10 @@ val_type inifile_fetch(inifile *dba, const key_type *key, int skip TSRMLS_DC) { if (!(res=inifile_key_cmp(&ln.key, key TSRMLS_CC))) { if (!skip) { val.value = estrdup(ln.val.value ? ln.val.value : ""); - /* allow faster access by automatically getting next key */ - inifile_read(dba, &ln TSRMLS_CC); + /* allow faster access by updating key read into next */ inifile_line_free(&dba->next); dba->next = ln; + dba->next.pos = php_stream_tell(dba->fp);; return val; } skip--;