Re: String Extension Proposal

From: Date: Sat, 02 Jul 2005 02:50:55 +0000
Subject: Re: String Extension Proposal
References: 1  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-2517@lists.php.net to get a copy of this message
I really don't see that the minimal performance improvements on the one special case where you are modifying the string in place warrants the complexity of a string class. I'd bet other overhead will eat away at the performance of even that special case. And the idea that $trimmedStr = $myStr->makeCopy()->trim; is somehow superior to: $trimmedStr = trim($myStr); just seems insane to me. So no, I'd be completely against letting this get anywhere near the core. -Rasmus Jessie Hernandez wrote: > Hello, I've started working on an extension which declares a String > class for PHP. I already have several methods completed and will add more as > I have time. The features of this String class are the following: > > Speed/Space Management > ---------------------- > Right now, when you perform an operation such as "$value = > strtoupper($value)", a copy of the string is made, uppercased, and then > returned. This copy is unnecessary, as the original string is going to be > replaced. In this String class, all operations are done in the current > buffer. Another example, a "trim" method call simply moves the > non-whitespace characters to the beginning of the string and terminates > (sets it to '\0') the string at the first whitespace chacter at the end of > the string. > > If a copy of the string is truly needed, then the "makeCopy()" method is > just for that. You can do "$myStr->trim()" to do in-line trimming or > "$trimmedStr = $myStr->makeCopy()->trim()" to preserve the original value. > > The start size and prealloc sizes for string buffers will be configurable > through INI options. A method "reserve()" exists to reserve a specific size > for the string. If a string expects to have a lot of concatenations, > reserve()'ing an appropriate size for the string will GREATLY increase > performance and space utilization. > > > Primitive String Compatibility > ----------------------------- > The following primitive string operations ALREADY work on the current class, > compiled against PHP 5.0.4! > > <code> > $myStr = new String( "Hello World!" ); > > // get single character > echo $myStr{1}; // prints 'e' > // interpolation! > echo "The contents are: $myStr"; //prints "The contents are: Hello World!" > // regular functions! > echo strrev( $myStr ); // prints "!dlroW olleH" > </code> > > > If there are no objections, I would like to post my code to PECL. This > extension only declares one class, "String", and is meant to only work in > PHP 5 and above. > > > Regards, > > Jessie Hernandez >

« previous php.pecl.dev (#2517) next »