[Mono-bugs] [Bug 59537][Nor] New - improve NameTable performance

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 3 Jun 2004 04:02:16 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by mordechait@mainsoft.com.

http://bugzilla.ximian.com/show_bug.cgi?id=59537

--- shadow/59537	2004-06-03 04:02:16.000000000 -0400
+++ shadow/59537.tmp.7250	2004-06-03 04:02:16.000000000 -0400
@@ -0,0 +1,50 @@
+Bug#: 59537
+Product: Mono: Class Libraries
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Sys.XML
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: mordechait@mainsoft.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: improve NameTable performance
+
+Description of Problem:
+System.Xml.NameTable.cs has two overloaded methods:
+Add(char[] ...) and Add(String)
+
+I think it is a cleaner code if the first method will delegate the call to
+ the second one (otherwise the hash code calculation is duplicated over the
+code)
+I found a performance booster: the calculation of hashcode in the Add
+methods is clearly a costly operation.
+I used the String.GetHashCode() instead and got good improvment in the Add
+method.
+The profiler did show impovement (from 4404ms to 1023ms).
+
+A faster way to calculate 'h' can be:
+...
+int h =key.GetHashCode();
+// h must be be >= 0
+h &= 0x7FFFFFFF;
+...
+
+
+for example:
+public override string Add (char [] key, int start, int len)
+{
+ if (((0 > start) && (start >= key.Length))|| ((0 > len) && (len >= 
+   key.Length - len))) throw new IndexOutOfRangeException ("The Index is 
+   out of range.");
+ if (len == 0) return String.Empty;
+ return Add(new string (key, start, len)); ---> here we delegate...
+}
+
+What do you say ?