Browse Source

Lock the document before adding rows to datagrid.

Locking the document prevents us from taking performance hit in the following chain of calls:

Element::InsertBefore ->
Element::DirtyStructure ->
ElementStyle::GetDefinition->
ElementStyle::UpdateDefinition ->
ElementDecoration::ReloadDecorators()
ElementDocument::UpdateLayout()

which did a full layout of the document
Victor Luchitz 13 years ago
parent
commit
af2c493455
1 changed files with 12 additions and 0 deletions
  1. 12 0
      Source/Controls/ElementDataGridRow.cpp

+ 12 - 0
Source/Controls/ElementDataGridRow.cpp

@@ -362,6 +362,10 @@ void ElementDataGridRow::AddChildren(int first_row_added, int num_rows_added)
 		first_row_added = (int)children.size();
 		first_row_added = (int)children.size();
 	}
 	}
 
 
+	// prevent relayout of the document while adding rows
+	Core::ElementDocument* document = parent_grid->GetOwnerDocument();
+	document->LockLayout(true);
+
 	// We need to make a row for each new child, then pass through the cell
 	// We need to make a row for each new child, then pass through the cell
 	// information and the child's data source (if one exists.)
 	// information and the child's data source (if one exists.)
 	if (data_source)
 	if (data_source)
@@ -392,6 +396,8 @@ void ElementDataGridRow::AddChildren(int first_row_added, int num_rows_added)
 		}
 		}
 	}
 	}
 
 
+	document->LockLayout(false);
+
 	RefreshChildDependentCells();
 	RefreshChildDependentCells();
 	DirtyRow();
 	DirtyRow();
 
 
@@ -408,6 +414,10 @@ void ElementDataGridRow::RemoveChildren(int first_row_removed, int num_rows_remo
 		num_rows_removed = (int)children.size() - first_row_removed;
 		num_rows_removed = (int)children.size() - first_row_removed;
 	}
 	}
 
 
+	// prevent relayout of the document while removing rows
+	Core::ElementDocument* document = parent_grid->GetOwnerDocument();
+	document->LockLayout(true);
+
 	for (int i = num_rows_removed - 1; i >= 0; i--)
 	for (int i = num_rows_removed - 1; i >= 0; i--)
 	{
 	{
 		children[first_row_removed + i]->RemoveChildren();
 		children[first_row_removed + i]->RemoveChildren();
@@ -421,6 +431,8 @@ void ElementDataGridRow::RemoveChildren(int first_row_removed, int num_rows_remo
 		children[i]->DirtyTableRelativeIndex();
 		children[i]->DirtyTableRelativeIndex();
 	}
 	}
 
 
+	document->LockLayout(false);
+
 	Rocket::Core::Dictionary parameters;
 	Rocket::Core::Dictionary parameters;
 	parameters.Set("first_row_removed", GetChildTableRelativeIndex(first_row_removed));
 	parameters.Set("first_row_removed", GetChildTableRelativeIndex(first_row_removed));
 	parameters.Set("num_rows_removed", num_rows_removed);
 	parameters.Set("num_rows_removed", num_rows_removed);