From: Ilia Alshanetsky Date: Sun, 6 Mar 2005 19:37:17 +0000 (+0000) Subject: MFH: Make html_entity_decode() 15-20% faster by avoiding pointless string X-Git-Tag: php-5.0.4RC1~67 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d74acc15ccdf8fe19fdbaf0db314c7bb8dceec14;p=php MFH: Make html_entity_decode() 15-20% faster by avoiding pointless string duplication. --- diff --git a/ext/standard/html.c b/ext/standard/html.c index 0b5d7c2235..e1ac9188bc 100644 --- a/ext/standard/html.c +++ b/ext/standard/html.c @@ -940,9 +940,11 @@ PHPAPI char *php_unescape_html_entities(unsigned char *old, int oldlen, int *new return 0; } - replaced = php_str_to_str(ret, retlen, entity, entity_length, replacement, replacement_len, &retlen); - efree(ret); - ret = replaced; + if (php_memnstr(ret, entity, entity_length, ret+retlen)) { + replaced = php_str_to_str(ret, retlen, entity, entity_length, replacement, replacement_len, &retlen); + efree(ret); + ret = replaced; + } } } } @@ -954,10 +956,12 @@ PHPAPI char *php_unescape_html_entities(unsigned char *old, int oldlen, int *new replacement[0] = (unsigned char)basic_entities[j].charcode; replacement[1] = '\0'; - - replaced = php_str_to_str(ret, retlen, basic_entities[j].entity, basic_entities[j].entitylen, replacement, 1, &retlen); - efree(ret); - ret = replaced; + + if (php_memnstr(ret, basic_entities[j].entity, basic_entities[j].entitylen, ret+retlen)) { + replaced = php_str_to_str(ret, retlen, basic_entities[j].entity, basic_entities[j].entitylen, replacement, 1, &retlen); + efree(ret); + ret = replaced; + } } /* replace numeric entities & "&" */