Răsfoiți Sursa

2008-07-02 Marek Habersack <[email protected]>

	* GridView.cs: minor optimizations (removed a foreach loop,
	replaced calls to Array.Length with a variable containing the
	length).

svn path=/trunk/mcs/; revision=107043
Marek Habersack 17 ani în urmă
părinte
comite
a5ecccea52

+ 6 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,9 @@
+2008-07-02  Marek Habersack  <[email protected]>
+
+	* GridView.cs: minor optimizations (removed a foreach loop,
+	replaced calls to Array.Length with a variable containing the
+	length).
+
 2008-06-30  Marek Habersack  <[email protected]>
 
 	* ObjectDataSourceView.cs, Menu.cs, DataList.cs,

+ 11 - 8
mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs

@@ -1271,13 +1271,16 @@ namespace System.Web.UI.WebControls
 
 			_dataEnumerator = null;
 			ICollection fieldCollection = CreateColumns (dataSource, dataBinding);
-			DataControlField[] fields = new DataControlField [fieldCollection.Count];
+			int fieldCount = fieldCollection.Count;
+			DataControlField dcf;
+			DataControlField[] fields = new DataControlField [fieldCount];
 			fieldCollection.CopyTo (fields, 0);
-
-			foreach (DataControlField field in fields) {
-				field.Initialize (AllowSorting, this);
+			
+			for (int i = 0; i < fieldCount; i++) {
+				dcf = fields [i];
+				dcf.Initialize (AllowSorting, this);
 				if (EnableSortingAndPagingCallbacks)
-					field.ValidateSupportsCallback ();
+					dcf.ValidateSupportsCallback ();
 			}
 
 			bool skip_first = false;
@@ -1298,7 +1301,7 @@ namespace System.Web.UI.WebControls
 				
 				if (list.Count == 0) {
 					if (createPager && (PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom)) {
-						topPagerRow = CreatePagerRow (fields.Length, dataSource);
+						topPagerRow = CreatePagerRow (fieldCount, dataSource);
 						OnRowCreated (new GridViewRowEventArgs (topPagerRow));
 						ContainedTable.Rows.Add (topPagerRow);
 						if (dataBinding) {
@@ -1336,7 +1339,7 @@ namespace System.Web.UI.WebControls
 			}
 
 			if (list.Count == 0) {
-				GridViewRow emptyRow = CreateEmptyrRow (fields.Length);
+				GridViewRow emptyRow = CreateEmptyrRow (fieldCount);
 				if (emptyRow != null) {
 					OnRowCreated (new GridViewRowEventArgs (emptyRow));
 					ContainedTable.Rows.Add (emptyRow);
@@ -1358,7 +1361,7 @@ namespace System.Web.UI.WebControls
 				}
 
 				if (createPager && (PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom)) {
-					bottomPagerRow = CreatePagerRow (fields.Length, dataSource);
+					bottomPagerRow = CreatePagerRow (fieldCount, dataSource);
 					OnRowCreated (new GridViewRowEventArgs (bottomPagerRow));
 					ContainedTable.Rows.Add (bottomPagerRow);
 					if (dataBinding) {