Improve stringpointer management in domainelementfactory

Issue #302 resolved
Bart Bogaerts created an issue

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)

  1. Bart Bogaerts reporter

    Addendum: removing all calls to stringpointer might be dangerous: we should guarantee that all those strings are never deleted!

  2. Log in to comment