Re: gcc 2.95 vs 3.21 performance

Hugo Mills
2003-02-05T00:54:15Z

[-- Attachment #1: Type: text/plain, Size: 2166 bytes --]

On Wed, Feb 05, 2003 at 12:51:12AM +0100, Jakob Oestergaard wrote:
> On Tue, Feb 04, 2003 at 03:21:01PM -0800, Larry McVoy wrote:
> > I can't offer any immediate help with this but I want the same thing. At
> > some point, we're planning on funding some extensions into GCC or whatever
> > reasonable C compiler is around:
> >
> > - regular expressions
> >
> > {
> > char *foo = "blech";
> >
> > if (foo =~ /regex are nice/) {
> > printf("Well isn't that special?\n");
> > }
> > }
>
> Ok, I can't help you with that.

I wanted something like that a while ago, so I wrote a couple of
classes in C++ to handle regexps. Some of the test code looks like
this:

string str = "fum foo";
rejex exp("f(o*)");
// Search for a regex
if( s/exp )
cout << "Found it!" << endl;
// Count matches
cout << s/exp << " matches" << endl;

replace rep("g$0");

// Search & replace
str/exp/rep;
cout << s << endl;

// All in one
"foo bar"/rejex("ba")/replace();

It's not perfect by any stretch of the imagination, but it works.
I've not released it, because I haven't had a chance to get it into a
releasable form yet. Actually, looking at it, I should probably play a
couple of tricks with overloading operators to give you instead

str =~ search/replace;

or even

"str" =~ "search"/"replace";

> You have probably seen a Perl program before... Now imagine a two
> million line Perl program... That is why the above is not a good idea ;)
>
> It's still your right to want it of course...

That's a good point, but I've always felt that the main problem
with perl isn't the regexes, but the rest of the language(*).

Hugo.

(*) Some may feel that, coming from a C++ programmer, this is a case
of the pot calling the kettle black. :)

--
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
PGP key: 1C335860 from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
--- Our so-called leaders speak/with words they try to jail ya/ ---
They subjugate the meek/but it's the rhetoric of failure.

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]