Browse Source

Performance: Change several maps and sets to unordered_*.

Michael 7 years ago
parent
commit
b86efd039b

+ 1 - 1
Include/Rocket/Core/BaseXMLParser.h

@@ -110,7 +110,7 @@ class ROCKETCORE_API BaseXMLParser
 		// The loose data being read.
 		String data;
 
-		std::set< String > cdata_tags;
+		std::unordered_set< String > cdata_tags;
 };
 
 }

+ 1 - 1
Include/Rocket/Core/Element.h

@@ -240,7 +240,7 @@ public:
 	/// Returns local 'width' and 'height' properties from element's style or local cache,
 	/// ignoring default values.
 	void GetLocalDimensionProperties(const Property **width, const Property **height);
-	/// Returns the size of the containing block.
+	/// Returns the size of the containing block. Often percentages are scaled relative to this.
 	Vector2f GetContainingBlock();
 	/// Returns 'overflow' properties' values from element's style or local cache.
 	void GetOverflow(int *overflow_x, int *overflow_y);

+ 1 - 1
Include/Rocket/Core/FontEffect.h

@@ -121,7 +121,7 @@ private:
 };
 
 typedef std::vector< FontEffect* > FontEffectList;
-typedef std::map< String, FontEffect* > FontEffectMap;
+typedef std::unordered_map< String, FontEffect* > FontEffectMap;
 
 }
 }

+ 1 - 1
Include/Rocket/Core/FontEffectInstancer.h

@@ -89,7 +89,7 @@ private:
 	PropertySpecification properties;
 
 	// Properties that define the geometry.
-	std::set< String > volatile_properties;
+	std::unordered_set< String > volatile_properties;
 
 	friend class Factory;
 };

+ 1 - 1
Include/Rocket/Core/FontFace.h

@@ -69,7 +69,7 @@ protected:
 	bool release_stream;
 
 	typedef std::vector< FontFaceHandle* > HandleList;
-	typedef std::map< int, HandleList > HandleMap;
+	typedef std::unordered_map< int, HandleList > HandleMap;
 	HandleMap handles;
 };
 

+ 1 - 1
Include/Rocket/Core/PropertyDictionary.h

@@ -34,7 +34,7 @@
 namespace Rocket {
 namespace Core {
 
-typedef std::map< String, Property > PropertyMap;
+typedef std::unordered_map< String, Property > PropertyMap;
 
 /**
 	A dictionary to property names to values.

+ 1 - 1
Include/Rocket/Core/PropertyParser.h

@@ -35,7 +35,7 @@
 namespace Rocket {
 namespace Core {
 
-typedef std::map< String, int, StringUtilities::StringComparei > ParameterMap;
+typedef std::map < String, int, StringUtilities::StringComparei > ParameterMap;
 
 /**
 	A property parser takes a property declaration in string form, validates it, and converts it to a Property.

+ 2 - 2
Include/Rocket/Core/PropertySpecification.h

@@ -107,8 +107,8 @@ public:
 	void SetPropertyDefaults(PropertyDictionary& dictionary) const;
 
 private:
-	typedef std::map< String, PropertyDefinition* > PropertyMap;
-	typedef std::map< String, PropertyShorthandDefinition* > ShorthandMap;
+	typedef std::unordered_map< String, PropertyDefinition* > PropertyMap;
+	typedef std::unordered_map< String, PropertyShorthandDefinition* > ShorthandMap;
 
 	PropertyMap properties;
 	ShorthandMap shorthands;

+ 16 - 0
Include/Rocket/Core/String.h

@@ -78,7 +78,23 @@ ROCKETCORE_API_INLINE bool StringBase< char >::operator!=(const char * compare)
 	#define strncasecmp strnicmp
 #endif
 
+struct hash_str_lowercase {
+	std::size_t operator()(const ::Rocket::Core::String& string) const
+	{
+		auto str_lower = string.ToLower();
+		return str_lower.Hash();
+	}
+};
 }
 }
 
+namespace std {
+	template <> struct hash<::Rocket::Core::String> {
+		std::size_t operator()(const ::Rocket::Core::String& string) const
+		{
+			return string.Hash();
+		}
+	};
+}
+
 #endif

+ 3 - 3
Include/Rocket/Core/StyleSheet.h

@@ -50,8 +50,8 @@ class StyleSheetNode;
 class ROCKETCORE_API StyleSheet : public ReferenceCountable
 {
 public:
-	typedef std::set< StyleSheetNode* > NodeList;
-	typedef std::map< String, NodeList > NodeIndex;
+	typedef std::unordered_set< StyleSheetNode* > NodeList;
+	typedef std::unordered_map< String, NodeList > NodeIndex;
 
 	StyleSheet();
 	virtual ~StyleSheet();
@@ -88,7 +88,7 @@ private:
 	// Map of every node, even empty, un-styled, nodes.
 	NodeIndex complete_node_index;
 
-	typedef std::map< String, ElementDefinition* > ElementDefinitionCache;
+	typedef std::unordered_map< String, ElementDefinition* > ElementDefinitionCache;
 	// Index of element addresses to element definitions.
 	mutable ElementDefinitionCache address_cache;
 	// Index of node sets to element definitions.

+ 1 - 1
Include/Rocket/Core/StyleSheetSpecification.h

@@ -110,7 +110,7 @@ private:
 	void RegisterDefaultProperties();
 
 	// Parsers used by all property definitions.
-	typedef std::map< String, PropertyParser* > ParserMap;
+	typedef std::unordered_map< String, PropertyParser* > ParserMap;
 	ParserMap parsers;
 
 	// The properties defined in the style sheet specification.

+ 4 - 2
Include/Rocket/Core/Types.h

@@ -37,7 +37,9 @@
 #include <limits.h>
 #include <string>
 #include <map>
+#include <unordered_map>
 #include <set>
+#include <unordered_set>
 #include <vector>
 
 #include "Platform.h"
@@ -102,8 +104,8 @@ typedef uintptr_t DecoratorDataHandle;
 // List of elements.
 typedef std::vector< Element* > ElementList;
 typedef std::set< String > PseudoClassList;
-typedef std::set< String > PropertyNameList;
-typedef std::set< String > AttributeNameList;
+typedef std::unordered_set< String > PropertyNameList;
+typedef std::unordered_set< String > AttributeNameList;
 typedef Dictionary ElementAttributes;
 typedef std::vector< ElementAnimation > ElementAnimationList;
 

+ 1 - 1
Include/Rocket/Core/URL.h

@@ -101,7 +101,7 @@ public:
 	const String& GetExtension() const;
 	
 	/// Access the url parameters
-	typedef std::map< String, String > Parameters;
+	typedef std::unordered_map< String, String > Parameters;
 	const Parameters& GetParameters() const;
 	void SetParameter(const String& name, const String& value);
 	void SetParameters( const Parameters& parameters );

+ 1 - 1
Source/Core/Core.cpp

@@ -49,7 +49,7 @@ static FileInterfaceDefault file_interface_default;
 #endif
 static bool initialised = false;
 
-typedef std::map< String, Context* > ContextMap;
+typedef std::unordered_map< String, Context* > ContextMap;
 static ContextMap contexts;
 
 #ifndef ROCKET_VERSION

+ 3 - 3
Source/Core/ElementStyle.cpp

@@ -447,13 +447,13 @@ float ElementStyle::ResolveNumberLengthPercent(const Property * property, Relati
 		base_value = element->GetContainingBlock().y;
 		break;
 	case RelativeTarget::FontSize:
-		base_value = (int)ElementUtilities::GetFontSize(element);
+		base_value = (float)ElementUtilities::GetFontSize(element);
 		break;
 	case RelativeTarget::ParentFontSize:
-		base_value = (int)ElementUtilities::GetFontSize(element->GetParentNode());
+		base_value = (float)ElementUtilities::GetFontSize(element->GetParentNode());
 		break;
 	case RelativeTarget::LineHeight:
-		base_value = (int)ElementUtilities::GetLineHeight(element);
+		base_value = (float)ElementUtilities::GetLineHeight(element);
 		break;
 	default:
 		break;

+ 2 - 0
Source/Core/ElementTextDefault.cpp

@@ -431,6 +431,8 @@ static bool BuildToken(WString& token, const word*& token_begin, const word* str
 {
 	ROCKET_ASSERT(token_begin != string_end);
 
+	token.Reserve(string_end - token_begin + token.Length());
+
 	// Check what the first character of the token is; all we need to know is if it is white-space or not.
 	bool parsing_white_space = StringUtilities::IsWhitespace(*token_begin);
 

+ 1 - 1
Source/Core/EventDispatcher.h

@@ -88,7 +88,7 @@ private:
 		bool in_capture_phase;
 	};
 	typedef std::vector< Listener > Listeners;
-	typedef std::map< String, Listeners > Events;
+	typedef std::unordered_map< String, Listeners > Events;
 	Events events;
 
 	void TriggerEvents(Event* event);

+ 3 - 3
Source/Core/Factory.cpp

@@ -56,15 +56,15 @@ namespace Rocket {
 namespace Core {
 
 // Element instancers.
-typedef std::map< String, ElementInstancer* > ElementInstancerMap;
+typedef std::unordered_map< String, ElementInstancer* > ElementInstancerMap;
 static ElementInstancerMap element_instancers;
 
 // Decorator instancers.
-typedef std::map< String, DecoratorInstancer* > DecoratorInstancerMap;
+typedef std::unordered_map< String, DecoratorInstancer* > DecoratorInstancerMap;
 static DecoratorInstancerMap decorator_instancers;
 
 // Font effect instancers.
-typedef std::map< String, FontEffectInstancer* > FontEffectInstancerMap;
+typedef std::unordered_map< String, FontEffectInstancer* > FontEffectInstancerMap;
 static FontEffectInstancerMap font_effect_instancers;
 
 // The context instancer.

+ 1 - 1
Source/Core/FontDatabase.cpp

@@ -38,7 +38,7 @@ namespace Core {
 FontDatabase* FontDatabase::instance = NULL;
 FontDatabase::FontProviderTable FontDatabase::font_provider_table;
 
-typedef std::map< String, FontEffect* > FontEffectCache;
+typedef std::unordered_map< String, FontEffect* > FontEffectCache;
 FontEffectCache font_effect_cache;
 
 FontDatabase::FontDatabase()

+ 2 - 2
Source/Core/FontFaceHandle.h

@@ -125,8 +125,8 @@ protected:
 	FontGlyphList glyphs;
 	FontKerningList kerning;
 
-	typedef std::map< const FontEffect*, FontFaceLayer* > FontLayerMap;
-	typedef std::map< String, FontFaceLayer* > FontLayerCache;
+	typedef std::unordered_map< const FontEffect*, FontFaceLayer* > FontLayerMap;
+	typedef std::unordered_map< String, FontFaceLayer* > FontLayerCache;
 	typedef std::vector< FontFaceLayer* > LayerConfiguration;
 	typedef std::vector< LayerConfiguration > LayerConfigurationList;
 

+ 1 - 1
Source/Core/PropertyParserColour.h

@@ -29,7 +29,7 @@
 #define ROCKETCOREPROPERTYPARSERCOLOUR_H
 
 #include "../../Include/Rocket/Core/PropertyParser.h"
-#include <map>
+#include <unordered_map>
 
 namespace Rocket {
 namespace Core {

+ 2 - 2
Source/Core/StyleSheetFactory.h

@@ -75,14 +75,14 @@ private:
 	StyleSheet* LoadStyleSheet(const String& sheet);
 
 	// Individual loaded stylesheets
-	typedef std::map<String, StyleSheet*> StyleSheets;
+	typedef std::unordered_map<String, StyleSheet*> StyleSheets;
 	StyleSheets stylesheets;
 
 	// Cache of combined style sheets
 	StyleSheets stylesheet_cache;
 
 	// Custom complex selectors available for style sheets.
-	typedef std::map< String, StyleSheetNodeSelector* > SelectorMap;
+	typedef std::unordered_map< String, StyleSheetNodeSelector* > SelectorMap;
 	SelectorMap selectors;
 };
 

+ 1 - 1
Source/Core/StyleSheetNode.h

@@ -145,7 +145,7 @@ private:
 	PropertyDictionary properties;
 
 	// This node's child nodes, whether standard tagged children, or further derivations of this tag by ID or class.
-	typedef std::map< String, StyleSheetNode* > NodeMap;
+	typedef std::unordered_map< String, StyleSheetNode* > NodeMap;
 	NodeMap children[NUM_NODE_TYPES];
 };
 

+ 1 - 1
Source/Core/TemplateCache.h

@@ -60,7 +60,7 @@ private:
 	TemplateCache();
 	~TemplateCache();
 
-	typedef std::map<String, Template*> Templates;
+	typedef std::unordered_map<String, Template*> Templates;
 	Templates templates;
 	Templates template_ids;
 };

+ 1 - 1
Source/Core/TextureDatabase.h

@@ -64,7 +64,7 @@ private:
 	TextureDatabase();
 	~TextureDatabase();
 
-	typedef std::map< String, TextureResource* > TextureMap;
+	typedef std::unordered_map< String, TextureResource* > TextureMap;
 	TextureMap textures;
 };
 

+ 1 - 1
Source/Core/TextureResource.h

@@ -77,7 +77,7 @@ private:
 	String source;
 
 	typedef std::pair< TextureHandle, Vector2i > TextureData;
-	typedef std::map< RenderInterface*, TextureData > TextureDataMap;
+	typedef std::unordered_map< RenderInterface*, TextureData > TextureDataMap;
 	mutable TextureDataMap texture_data;
 };
 

+ 1 - 1
Source/Core/XMLParser.cpp

@@ -34,7 +34,7 @@
 namespace Rocket {
 namespace Core {
 
-typedef std::map< String, XMLNodeHandler* > NodeHandlers;
+typedef std::unordered_map< String, XMLNodeHandler* > NodeHandlers;
 static NodeHandlers node_handlers;
 static XMLNodeHandler* default_node_handler = NULL;
 

+ 1 - 1
Source/Debugger/Plugin.h

@@ -125,7 +125,7 @@ private:
 	bool render_outlines;
 
 	// Keep track of instanced elements for leak tracking.
-	typedef std::set< Core::Element* > ElementInstanceMap;
+	typedef std::unordered_set< Core::Element* > ElementInstanceMap;
 	ElementInstanceMap elements;
 
 	// Singleton instance