Ver Fonte

Element destructor optimization

Michael Ragazzon há 6 anos atrás
pai
commit
336d696311
2 ficheiros alterados com 15 adições e 14 exclusões
  1. 2 1
      Samples/basic/benchmark/src/main.cpp
  2. 13 13
      Source/Core/Element.cpp

+ 2 - 1
Samples/basic/benchmark/src/main.cpp

@@ -102,6 +102,7 @@ public:
 		  (After Windows feature update and MSVC update, no code change): 109.0  [0bba316]
 		  Fixes and element style iterators: 108.0  [0bba316]
 		  Update definition speedup: 115.0  [5d138fa]
+		  (Release mode, no code change): 135.0  [5d138fa]
 		  
 		*/
 
@@ -184,7 +185,7 @@ void GameLoop()
 		single_loop = false;
 	}
 
-	static constexpr int buffer_size = 100;
+	static constexpr int buffer_size = 200;
 	static float fps_buffer[buffer_size] = {};
 	static int buffer_index = 0;
 

+ 13 - 13
Source/Core/Element.cpp

@@ -174,22 +174,22 @@ Element::~Element()
 	// Remove scrollbar elements before we delete the children!
 	scroll->ClearScrollbars();
 
-	while (!children.empty())
+	// A simplified version of RemoveChild() for destruction.
+	for (Element* child : children)
 	{
-		// A simplified version of RemoveChild() for destruction.
-		Element* child = children.front();
-
-		Element* ancestor = child;
-		for (int i = 0; i <= ChildNotifyLevels && ancestor; i++, ancestor = ancestor->GetParentNode())
-			ancestor->OnChildRemove(child);
-
-		if (num_non_dom_children > 0)
-			num_non_dom_children--;
-
-		deleted_children.push_back(child);
-		children.erase(children.begin());
+		Element* child_ancestor = child;
+		for (int i = 0; i <= ChildNotifyLevels && child_ancestor; i++, child_ancestor = child_ancestor->GetParentNode())
+			child_ancestor->OnChildRemove(child);
 	}
 
+	if (deleted_children.empty())
+		deleted_children = std::move(children);
+	else
+		deleted_children.insert(deleted_children.end(), children.begin(), children.end());
+	
+	children.clear();
+	num_non_dom_children = 0;
+
 	// Release all deleted children.
 	ReleaseElements(deleted_children);