Re: String Extension Proposal

From: Date: Sat, 02 Jul 2005 16:27:41 +0000
Subject: Re: String Extension Proposal
References: 1 2  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-2523@lists.php.net to get a copy of this message
On 7/2/05, Rasmus Lerdorf <rasmus@lerdorf.com> wrote: > 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; Looks to me a bit similar to python syntax: trimmedstr = mystr.trim() which can get hairy when users put as many things into one line of code rather than over multiple lines. > > 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. I'll second that ;) Regards --jm > > -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 -- Jacques Marneweck http://www.powertrip.co.za/blog/

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