Skip to content

Commit 1512e18

Browse files
jaladreipsigcbot
authored andcommitted
Fix some issue with RT API UnorderedMap
Fix some issue with RT API UnorderedMap
1 parent 5a47189 commit 1512e18

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

IGC/AdaptorCommon/RayTracing/API/ADT/Array.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ template <typename T> class Array {
114114
End = Start + NumElts;
115115

116116
for (uint32_t i = 0; i < NumElts; i++)
117-
Start[i] = typename iterator::value_type();
117+
new (&Start[i]) typename iterator::value_type;
118118
}
119119

120120
Array &operator=(const Array &) = delete;

IGC/AdaptorCommon/RayTracing/API/ADT/UnorderedMap.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,24 @@ class UnorderedMap {
9494
if (idx < Keys.size()) {
9595
Values[idx] = std::move(value);
9696
} else {
97-
// Grow arrays by 1
98-
Array<KeyT> newKeys(Keys.size() + 1);
99-
Array<ValueT> newValues(Values.size() + 1);
100-
for (size_t i = 0; i < Keys.size(); ++i) {
101-
newKeys[i] = Keys[i];
102-
newValues[i] = std::move(Values[i]);
97+
uint32_t currSize = Keys.size();
98+
99+
Array<KeyT> oldKeys = std::move(Keys);
100+
Array<ValueT> oldValues = std::move(Values);
101+
102+
Keys = Array<KeyT>(currSize + 1);
103+
Values = Array<ValueT>(currSize + 1);
104+
105+
for (uint32_t i = 0; i < currSize; ++i) {
106+
Keys[i] = std::move(oldKeys[i]);
107+
Values[i] = std::move(oldValues[i]);
103108
}
104-
newKeys[Keys.size()] = key;
105-
newValues[Values.size()] = std::move(value);
106-
Keys.destroy();
107-
Values.destroy();
108-
Keys = std::move(newKeys);
109-
Values = std::move(newValues);
109+
110+
Keys[currSize] = key;
111+
Values[currSize] = std::move(value);
112+
113+
oldKeys.destroy();
114+
oldValues.destroy();
110115
}
111116
}
112117

0 commit comments

Comments
 (0)