Re: gcc 2.95 vs 3.21 performance

Hugo Mills (hugo-lkml@carfax.org.uk)
Wed, 5 Feb 2003 01:03:44 +0000


This is a MIME-formatted message. If you see this text it means that your
E-mail software does not support MIME-formatted messages.

--=_courier-27626-1044407139-0001-2
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

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.        
                                                                         

--=_courier-27626-1044407139-0001-2 Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit Content-Disposition: inline

-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.0 (GNU/Linux)

iD8DBQE+QGLwssJ7whwzWGARAo4KAKCjutuCnjF5sK0tWLI/6WF3zX53+gCgjLt9 76hxwxh8qXaDNe/lskMB1pU= =tZtj -----END PGP SIGNATURE-----

--=_courier-27626-1044407139-0001-2--