Skip to content

Conversation

yohgaki
Copy link
Contributor

@yohgaki yohgaki commented Jun 23, 2015

Current php_html_entities() convert int/float/etc to string, then convert it.
int/float/etc is not required to be escaped. Optimize it by simply converting them to string.

Simple benchmark shows about 60% execution time reduction.

[yohgaki@dev github-php-src]$ ./php-bin b.php
Time: 10.484607934952
[yohgaki@dev github-php-src]$ ./php-bin b.php
Time: 10.867615222931
[yohgaki@dev github-php-src]$ ./php.new b.php
Time: 3.9379420280457
[yohgaki@dev github-php-src]$ ./php.new b.php
Time: 4.0694711208344
[yohgaki@dev github-php-src]$ cat b.php

@laruence
Copy link
Member

as I replied via mail, just for the record:
"But passing an non-string to htmlspecialchars are not common used cases..

"optimize" not common used cases... will bring nothing to us.. "

@yohgaki
Copy link
Contributor Author

yohgaki commented Jun 23, 2015

@laruence
It will not be rare since PHP7 has scalar type hint. There are many cases users must output width, height, age, month, numeric ID, etc.
BTW, I noticed that current test script didn't consider scalar value parameter well and the patch has problem with it. I'll fix if we decide to have this optimization.

@smalyshev smalyshev added Feature and removed Quickfix labels Jul 5, 2015
@nikic
Copy link
Member

nikic commented Mar 3, 2016

Closing as the reception of this change on the mailing list was clearly negative.

For reference: http://markmail.org/message/dmggiip2vhaqxmqu

@nikic nikic closed this Mar 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants