Sfoglia il codice sorgente

Avoid duplicate conversion to lowercase

Michael Ragazzon 6 anni fa
parent
commit
dec4ef6af6

+ 2 - 2
Source/Core/Element.cpp

@@ -115,10 +115,10 @@ struct alignas(ElementMeta) ElementMetaChunk
 
 
 
 
 /// Constructs a new libRocket element.
 /// Constructs a new libRocket element.
-Element::Element(const String& _tag) : relative_offset_base(0, 0), relative_offset_position(0, 0), absolute_offset(0, 0), scroll_offset(0, 0), content_offset(0, 0), content_box(0, 0), 
+Element::Element(const String& tag) : tag(tag), relative_offset_base(0, 0), relative_offset_position(0, 0), absolute_offset(0, 0), scroll_offset(0, 0), content_offset(0, 0), content_box(0, 0), 
 transform_state(), transform_state_perspective_dirty(true), transform_state_transform_dirty(true), transform_state_parent_transform_dirty(true), dirty_animation(false)
 transform_state(), transform_state_perspective_dirty(true), transform_state_transform_dirty(true), transform_state_parent_transform_dirty(true), dirty_animation(false)
 {
 {
-	tag = ToLower(_tag);
+	ROCKET_ASSERT(tag == ToLower(tag));
 	parent = NULL;
 	parent = NULL;
 	focus = NULL;
 	focus = NULL;
 	instancer = NULL;
 	instancer = NULL;

+ 1 - 1
Source/Core/ElementStyle.cpp

@@ -1319,7 +1319,7 @@ void ElementStyle::ComputeValues(Style::ComputedValues& values, const Style::Com
 			values.opacity = p->Get<float>();
 			values.opacity = p->Get<float>();
 
 
 		else if (name == FONT_FAMILY)
 		else if (name == FONT_FAMILY)
-			values.font_family = p->Get<String>();
+			values.font_family = ToLower(p->Get<String>());
 		else if (name == FONT_CHARSET)
 		else if (name == FONT_CHARSET)
 			values.font_charset = p->Get<String>();
 			values.font_charset = p->Get<String>();
 		else if (name == FONT_STYLE)
 		else if (name == FONT_STYLE)

+ 1 - 1
Source/Core/EventDispatcher.h

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

+ 2 - 2
Source/Core/FontProvider.cpp

@@ -35,8 +35,8 @@ namespace Core {
 // Returns a handle to a font face that can be used to position and render text.
 // Returns a handle to a font face that can be used to position and render text.
 Rocket::Core::FontFaceHandle* FontProvider::GetFontFaceHandle(const String& family, const String& charset, Font::Style style, Font::Weight weight, int size)
 Rocket::Core::FontFaceHandle* FontProvider::GetFontFaceHandle(const String& family, const String& charset, Font::Style style, Font::Weight weight, int size)
 {
 {
-	String family_lower = ToLower(family);
-	FontFamilyMap::iterator iterator = font_families.find(family_lower);
+	ROCKET_ASSERTMSG(family == ToLower(family), "Font family name must be converted to lowercase before entering here.");
+	FontFamilyMap::iterator iterator = font_families.find(family);
 	if (iterator == font_families.end())
 	if (iterator == font_families.end())
 		return NULL;
 		return NULL;
 
 

+ 2 - 2
Source/Core/StyleSheetNode.cpp

@@ -309,8 +309,8 @@ bool StyleSheetNode::IsApplicable(const Element* element) const
 	// Determine the tag (and possibly id / class as well) of the next required parent in the RCSS hierarchy.
 	// Determine the tag (and possibly id / class as well) of the next required parent in the RCSS hierarchy.
 	const StyleSheetNode* parent_node = parent;
 	const StyleSheetNode* parent_node = parent;
 	const String* ancestor_id = nullptr;
 	const String* ancestor_id = nullptr;
-	thread_local std::vector<const String*> ancestor_classes;
-	thread_local std::vector<const String*> ancestor_pseudo_classes;
+	static std::vector<const String*> ancestor_classes;
+	static std::vector<const String*> ancestor_pseudo_classes;
 	ancestor_classes.clear();
 	ancestor_classes.clear();
 	ancestor_pseudo_classes.clear();
 	ancestor_pseudo_classes.clear();
 	std::vector< const StyleSheetNode* > ancestor_structural_pseudo_classes;
 	std::vector< const StyleSheetNode* > ancestor_structural_pseudo_classes;