Skip to content

Commit ce2655a

Browse files
committed
fix ID map
1 parent f95d465 commit ce2655a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/protocols/types/ColorManagement.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace NColorManagement {
55
static uint32_t lastImageID = 0;
6-
static std::map<SImageDescription, uint32_t> knownDescriptionIds; // expected to be small1
6+
static std::map<uint32_t, SImageDescription> knownDescriptionIds; // expected to be small
77

88
const SPCPRimaries& getPrimaries(ePrimaries name) {
99
switch (name) {
@@ -21,22 +21,25 @@ namespace NColorManagement {
2121
}
2222
}
2323

24+
// TODO make image descriptions immutable and always set an id
25+
2426
uint32_t SImageDescription::findId() const {
25-
const auto known = knownDescriptionIds.find(*this);
26-
if (known != knownDescriptionIds.end())
27-
return known->second;
28-
else {
29-
const auto newId = ++lastImageID;
30-
knownDescriptionIds.insert(std::make_pair(*this, newId));
31-
return newId;
27+
for (auto it = knownDescriptionIds.begin(); it != knownDescriptionIds.end(); ++it) {
28+
if (it->second == *this)
29+
return it->first;
3230
}
31+
32+
const auto newId = ++lastImageID;
33+
knownDescriptionIds.insert(std::make_pair(newId, *this));
34+
return newId;
3335
}
3436

3537
uint32_t SImageDescription::getId() const {
3638
return id > 0 ? id : findId();
3739
}
3840

3941
uint32_t SImageDescription::updateId() {
42+
id = 0;
4043
id = findId();
4144
return id;
4245
}

0 commit comments

Comments
 (0)