Improve stringpointer management in domainelementfactory
Currently, the DEF assumes that stringpointers are unique.
This assumption could be taken away by calling the StringPointer method itself.
To avoid to much overhead, we suggest the following code
DomainElement element; auto it = _stringelements.find(value); if (it == _stringelements.cend()) { auto sharedstring = StringPointer(value); auto it2 = _stringelements.find(sharedstring); if (it2 == _stringelements.cend()) { element = new DomainElement(sharedstring); _stringelements[sharedstring] = element; } } else { element = it->second; } return element;
And deleting all other calls to StringPointer().
This code should be tested etcetera
Comments (4)
-
reporter -
- changed title to Improve stringpointer management in domainelementfactory
-
- changed status to resolved
Fixes
#302: Internalized StringPointer, simplifying code.→ <<cset 8897e30ba407>>
-
reporter Fixes
#302: Internalized StringPointer, simplifying code.→ <<cset 535c2174de08>>
- Log in to comment
Addendum: removing all calls to stringpointer might be dangerous: we should guarantee that all those strings are never deleted!