cvs: php4 /ext/standard string.c
| From: | Sascha Schumann | Date: | Thu, 12 Oct 2000 01:26:27 +0000 |
| Subject: | cvs: php4 /ext/standard string.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-2026@lists.php.net to get a copy of this message | ||
sas Wed Oct 11 18:26:27 2000 EDT
Modified files:
/php4/ext/standard string.c
Log:
Let strtr() use smart_str to reduce complexity
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.162 php4/ext/standard/string.c:1.163
--- php4/ext/standard/string.c:1.162 Wed Oct 11 17:50:28 2000
+++ php4/ext/standard/string.c Wed Oct 11 18:26:26 2000
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: string.c,v 1.162 2000/10/12 00:50:28 sas Exp $ */
+/* $Id: string.c,v 1.163 2000/10/12 01:26:26 sas Exp $ */
/* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
@@ -35,6 +35,7 @@
#include "zend_execute.h"
#include "php_globals.h"
#include "basic_functions.h"
+#include "php_smart_str.h"
#define STR_PAD_LEFT 0
#define STR_PAD_RIGHT 1
@@ -1462,9 +1463,10 @@
zval ctmp;
ulong num_key;
int minlen = 128*1024;
- int maxlen = 0, pos, len, newpos, newlen, found;
- char *newstr, *key;
+ int maxlen = 0, pos, len, found;
+ char *key;
HashPosition hpos;
+ smart_str result = {0};
zend_hash_internal_pointer_reset_ex(hash, &hpos);
while (zend_hash_get_current_data_ex(hash, (void **)&entry, &hpos) == SUCCESS) {
@@ -1490,11 +1492,9 @@
}
zend_hash_move_forward_ex(hash, &hpos);
}
-
+
key = emalloc(maxlen+1);
- newstr = emalloc(8192);
- newlen = 8192;
- newpos = pos = 0;
+ pos = 0;
while (pos < slen) {
if ((pos + maxlen) > slen) {
@@ -1523,13 +1523,7 @@
tlen = (*trans)->value.str.len;
}
- if ((newpos + tlen + 1) > newlen) {
- newlen = newpos + tlen + 1 + 8192;
- newstr = erealloc(newstr,newlen);
- }
-
- memcpy(newstr+newpos,tval,tlen);
- newpos += tlen;
+ smart_str_appendl(&result, tval, tlen);
pos += len;
found = 1;
@@ -1541,18 +1535,13 @@
}
if (! found) {
- if ((newpos + 1) > newlen) {
- newlen = newpos + 1 + 8192;
- newstr = erealloc(newstr,newlen);
- }
-
- newstr[ newpos++ ] = str[ pos++ ];
+ smart_str_appendc(&result, str[pos++]);
}
}
efree(key);
- newstr[ newpos ] = 0;
- RETURN_STRINGL(newstr,newpos,0);
+ smart_str_0(&result);
+ RETVAL_STRINGL(result.c,result.len,0);
}
/* {{{ proto string strtr(string str, string from, string to)
@@ -2047,8 +2036,6 @@
}
*target = 0;
}
-
-#include "php_smart_str.h"
PHPAPI char *php_str_to_str(char *haystack, int length,
char *needle, int needle_len, char *str, int str_len, int *_new_length)