From: Dion O. <dol...@us...> - 2005-12-20 22:48:20
|
Update of /cvsroot/magicajax/magicajax/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23742/magicajax/Core Modified Files: MagicAjaxModule.cs PageFilter.cs Util.cs Log Message: Made all RegEx's used by MagicAjax global in MagicAjaxModule.cs. This improves performance with factor 15. Note: only the RegEx's used for filtering WebPartManager script is not made global yet. Index: PageFilter.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/PageFilter.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PageFilter.cs 20 Dec 2005 13:11:08 -0000 1.6 --- PageFilter.cs 20 Dec 2005 22:48:12 -0000 1.7 *************** *** 66,69 **** --- 66,70 ---- /// <summary> /// Look for javascript generated for draggable webparts (IE only), and returns these javascripts. + /// TODO: make used regular expressions global /// </summary> public string GetWebPartManagerScriptValue(string formID) Index: Util.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/Util.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Util.cs 12 Dec 2005 12:10:41 -0000 1.16 --- Util.cs 20 Dec 2005 22:48:12 -0000 1.17 *************** *** 52,56 **** { StringBuilder sb = new StringBuilder(html); ! MatchCollection scriptMatches = Regex.Matches(html, ScriptPattern, RegexOptions.IgnoreCase); int diff = 0; --- 52,59 ---- { StringBuilder sb = new StringBuilder(html); ! ! Regex regEx = MagicAjaxModule.ScriptPattern; ! MatchCollection scriptMatches = regEx.Matches(html); ! //MatchCollection scriptMatches = Regex.Matches(html, ScriptPattern, RegexOptions.IgnoreCase); int diff = 0; *************** *** 112,117 **** { StringBuilder strbuild = new StringBuilder(html); ! RegexOptions options = RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.ExplicitCapture; ! Regex regEx = new System.Text.RegularExpressions.Regex(Util.FormElementPattern, options); MatchCollection matches = regEx.Matches(html); int diff = 0; --- 115,119 ---- { StringBuilder strbuild = new StringBuilder(html); ! Regex regEx = MagicAjaxModule.FormElementOptionsRegEx; MatchCollection matches = regEx.Matches(html); int diff = 0; *************** *** 198,202 **** case "select": Group selInner = match.Groups["inner"]; ! Regex regExOpt = new System.Text.RegularExpressions.Regex(@"<option.*?(?<selected>selected=(""|'|)selected(""|'|)(\s+|(?=>))).*?>", options); //now remove the 'selected' attributes within this <select> tag --- 200,204 ---- case "select": Group selInner = match.Groups["inner"]; ! Regex regExOpt = MagicAjaxModule.FormElementOptionSelectedRegEx; //now remove the 'selected' attributes within this <select> tag Index: MagicAjaxModule.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/MagicAjaxModule.cs,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** MagicAjaxModule.cs 18 Dec 2005 16:44:46 -0000 1.43 --- MagicAjaxModule.cs 20 Dec 2005 22:48:12 -0000 1.44 *************** *** 60,63 **** --- 60,89 ---- private MagicAjaxContext _magicAjaxContext; + #region Global Regular Expressions + private static RegexOptions options = RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.ExplicitCapture; + private Regex _formElementRegEx = new Regex(Util.FormElementPattern, options); + private Regex _formElementOptionsRegEx = new Regex("<option\\s((?<attrname>[-\\w]+)=\"(?<attrvalue>.*?)\"\\s?)*\\s*>.*?</option>", options); + private Regex _formElementOptionSelectedRegEx = new Regex(@"<option.*?(?<selected>selected=(""|'|)selected(""|'|)(\s+|(?=>))).*?>", options); + private Regex _scriptPattern = new Regex(Util.ScriptPattern, RegexOptions.IgnoreCase); + + public static Regex FormElementRegEx + { + get { return (Regex)HttpContext.Current.Items["FormElementRegEx"]; } + } + public static Regex FormElementOptionsRegEx + { + get { return (Regex)HttpContext.Current.Items["FormElementOptionsRegEx"]; } + } + public static Regex FormElementOptionSelectedRegEx + { + get { return (Regex)HttpContext.Current.Items["FormElementOptionSelectedRegEx"]; } + } + public static Regex ScriptPattern + { + get { return (Regex)HttpContext.Current.Items["ScriptPattern"]; } + } + + #endregion + #region IHttpModule implementation /// <summary> *************** *** 397,400 **** --- 423,432 ---- _response = context.Response; + // Init global Regular Expressions + context.Items.Add("FormElementRegEx", _formElementRegEx); + context.Items.Add("FormElementOptionsRegEx", _formElementOptionsRegEx); + context.Items.Add("FormElementOptionSelectedRegEx", _formElementOptionSelectedRegEx); + context.Items.Add("ScriptPattern", _scriptPattern); + // Create a new context and add it to the items collection for later retrieval // by MagicAjaxContext.Current |