[wp-trac] [WordPress Trac] #14429: Faster is_serialized

WordPress Trac wp-trac at lists.automattic.com
Thu Sep 23 00:08:39 UTC 2010


#14429: Faster is_serialized
--------------------------+-------------------------------------------------
 Reporter:  sambauers     |       Owner:           
     Type:  enhancement   |      Status:  new      
 Priority:  normal        |   Milestone:  3.1      
Component:  Optimization  |     Version:  3.0      
 Severity:  minor         |    Keywords:  has-patch
--------------------------+-------------------------------------------------

Comment(by hakre):

 Replying to [comment:10 Denis-de-Bernardy]:
 I like the direction you point to, strpbrk() is probably doing too much
 for our serialized case here.

 I replace the in_array call with strpos of which I assume (not know) it's
 faster.

 {{{
 if ( 2 > strlen($data[1]) && ':' === $data[1] && false !==
 strpos('adObis', $data[0])) {
 }}}

 Using that approach does save us from function_exists and strpbk
 overheads.





 if ( isset($data[1]) && $data[1] == ':' && in_array($data[0], array('a',
 'd', 'O', 'b', 'i', 's') )
 > r15636 honestly doesn't seem to make any sense. Shouldn't we be using
 something more like this?
 >
 > {{{
 > if ( isset($data[1]) && $data[1] == ':' && strpbrk($data[0],'adObis') ==
 $data[0] ) {
 > }}}
 >
 > or even:
 >
 >
 >
 > It's like... there's absolutely no point in a) calculating the length of
 a 1MB string to verifying that its second char is set, b) doing some
 complex comparison involving strpbrk() (which could potentially amount to
 finding the first of these chars at the very end of a 1MB string) and c)
 only *then* verifying that the second character works for our sake.
 >
 > Better: a) check that the second character exists at all, b) verify that
 it works, and c) finally look at the first chars to see if it works...
 >
 > My $.02...

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/14429#comment:13>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list