]> granicus.if.org Git - php/commitdiff
MFH: Make html_entity_decode() 15-20% faster by avoiding pointless string
authorIlia Alshanetsky <iliaa@php.net>
Sun, 6 Mar 2005 19:37:17 +0000 (19:37 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Sun, 6 Mar 2005 19:37:17 +0000 (19:37 +0000)
duplication.

ext/standard/html.c

index 0b5d7c2235c5202b8405c85788be81cde603b314..e1ac9188bc74624bd1aa2e700ba1afcd900803c7 100644 (file)
@@ -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 & "&amp;" */