[Mono-dev] MS/Mono incompatibility in System.Web.HttpRequest

Luca kronos.it at gmail.com
Mon Feb 13 16:49:58 EST 2006


Il Mon, Feb 13, 2006 at 11:20:53AM -0900, Joshua Kugler ha scritto: 
> On Monday 13 February 2006 11:12, Alex Chudnovsky wrote:
> > Edward C. Eisenbrey wrote:
> > >using System.Text.RegularExpressions;
> > >
> > >static bool CheckString (string val)
> > >{
> > >	Regex regex = new Regex("<[a-zA-Z\\!]+");
> > >	Match match = regex.Match(val);
> > >	return match.Success;
> > >}
> >
> > Pardon my instrusion, but would it not be better performance wise to
> > create static instance of the regexp to avoid doing it every time
> > CheckString called? Ie:
> >
> > static Regex regex = new Regex("<[a-zA-Z\\!]+");
> >
> > static bool CheckString (string val)
> > {
> >
> > 	Match match = regex.Match(val);
> > 	return match.Success;
> > }
> 
> Or at least declare it static in the sub (I assume you can do that)?

Well, no :) The "sub" is a method, so the regex object must be a static
member of the class. Back on the original topic, if that codepath is realy
performance critical you can even compile the Regex:

new Regex("<[a-zA->\\!]+", RegexOptions.Compiled);

Luca
-- 
Home: http://kronoz.cjb.net
La differenza fra l'intelligenza e la stupidita`?
All'intelligenza c'e` un limite.



More information about the Mono-devel-list mailing list