summaryrefslogtreecommitdiffstats
path: root/src/style.cpp
diff options
context:
space:
mode:
authorThomas Holder <thomas@thomas-holder.de>2018-12-22 20:14:32 +0000
committerThomas Holder <thomas@thomas-holder.de>2018-12-24 12:21:19 +0000
commitbbb920113f84ab5778784dfce40161a8f59cfa59 (patch)
tree0f8ca88addb5dd2220b93d8b7f59d496559a21b2 /src/style.cpp
parentStandard: Cpp11 (diff)
downloadinkscape-bbb920113f84ab5778784dfce40161a8f59cfa59.tar.gz
inkscape-bbb920113f84ab5778784dfce40161a8f59cfa59.zip
sp_attribute_lookup with std::map
- replace linear array search with std::map lookup - remove duplicated name lookup logic in SPStylePropHelper
Diffstat (limited to 'src/style.cpp')
-rw-r--r--src/style.cpp15
1 files changed, 3 insertions, 12 deletions
diff --git a/src/style.cpp b/src/style.cpp
index aab8f2695..b11a92749 100644
--- a/src/style.cpp
+++ b/src/style.cpp
@@ -76,7 +76,7 @@ static CRSelEng *sp_repr_sel_eng();
class SPStylePropHelper {
SPStylePropHelper() {
#define REGISTER_PROPERTY(id, member, name) \
- _register(reinterpret_cast<SPIBasePtr>(&SPStyle::member), id, name)
+ _register(reinterpret_cast<SPIBasePtr>(&SPStyle::member), id) /* name unused */
// SVG 2: Attributes promoted to properties
REGISTER_PROPERTY(SP_ATTR_D, d, "d");
@@ -215,11 +215,7 @@ public:
* Get property pointer by name
*/
SPIBase *get(SPStyle *style, const std::string &name) {
- auto it = m_name_map.find(name);
- if (it != m_name_map.end()) {
- return _get(style, it->second);
- }
- return nullptr;
+ return get(style, sp_attribute_lookup(name.c_str()));
}
/**
@@ -238,19 +234,14 @@ public:
private:
SPIBase *_get(SPStyle *style, SPIBasePtr ptr) { return &(style->*ptr); }
- void _register(SPIBasePtr ptr, SPAttributeEnum id, const char *name) {
+ void _register(SPIBasePtr ptr, SPAttributeEnum id) {
m_vector.push_back(ptr);
if (id != SP_ATTR_INVALID) {
m_id_map[id] = ptr;
}
-
- if (name[0]) {
- m_name_map[name] = ptr;
- }
}
- std::unordered_map<std::string, SPIBasePtr> m_name_map;
std::unordered_map</* SPAttributeEnum */ int, SPIBasePtr> m_id_map;
std::vector<SPIBasePtr> m_vector;
};