Skip to content

Commit 7c5666c

Browse files
authored
fix: Fix AnyMap not overwriting keys (#1204)
1 parent 52ae0c2 commit 7c5666c

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

packages/react-native-nitro-modules/cpp/core/AnyMap.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,28 +164,28 @@ AnyValue AnyMap::getAny(const std::string& key) const {
164164

165165
// Set
166166
void AnyMap::setNull(const std::string& key) {
167-
_map.emplace(key, nitro::null);
167+
_map.insert_or_assign(key, nitro::null);
168168
}
169169
void AnyMap::setDouble(const std::string& key, double value) {
170-
_map.emplace(key, value);
170+
_map.insert_or_assign(key, value);
171171
}
172172
void AnyMap::setBoolean(const std::string& key, bool value) {
173-
_map.emplace(key, value);
173+
_map.insert_or_assign(key, value);
174174
}
175175
void AnyMap::setBigInt(const std::string& key, int64_t value) {
176-
_map.emplace(key, value);
176+
_map.insert_or_assign(key, value);
177177
}
178178
void AnyMap::setString(const std::string& key, const std::string& value) {
179-
_map.emplace(key, value);
179+
_map.insert_or_assign(key, value);
180180
}
181181
void AnyMap::setArray(const std::string& key, const AnyArray& value) {
182-
_map.emplace(key, value);
182+
_map.insert_or_assign(key, value);
183183
}
184184
void AnyMap::setObject(const std::string& key, const AnyObject& value) {
185-
_map.emplace(key, value);
185+
_map.insert_or_assign(key, value);
186186
}
187187
void AnyMap::setAny(const std::string& key, const AnyValue& value) {
188-
_map.emplace(key, value);
188+
_map.insert_or_assign(key, value);
189189
}
190190

191191
// C++ getter

packages/react-native-nitro-modules/cpp/prototype/Prototype.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,12 @@ struct Prototype final {
6060
static std::shared_ptr<Prototype> get(const NativeInstanceId& typeId, const std::shared_ptr<Prototype>& base = nullptr) {
6161
static std::unordered_map<NativeInstanceId, std::shared_ptr<Prototype>> _prototypesCache;
6262

63-
const auto& found = _prototypesCache.find(typeId);
64-
if (found != _prototypesCache.end()) {
65-
// We know this C++ type ID / Prototype - return it!
66-
return found->second;
67-
} else {
63+
auto [it, inserted] = cache.try_emplace(typeId);
64+
if (inserted) {
6865
// This is the first time we see this C++ type ID - create a new base Prototype for this.
69-
auto prototype = std::shared_ptr<Prototype>(new Prototype(typeId, base));
70-
_prototypesCache.emplace(typeId, prototype);
71-
return prototype;
66+
it->second = std::shared_ptr<Prototype>(new Prototype(typeId, base));
7267
}
68+
return it->second;
7369
}
7470

7571
public:

packages/react-native-nitro-modules/cpp/threading/ThreadPool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ void ThreadPool::run(std::function<void()>&& task) {
6464
}
6565
// New scope because of RAII lock
6666
{
67-
// lock on the mutex - we want to emplace the task back in the queue
67+
// lock on the mutex - we want to push the task back in the queue
6868
std::unique_lock<std::mutex> lock(_queueMutex);
6969
if (!_isAlive) {
7070
throw std::runtime_error("Cannot queue the given task - the ThreadPool has already been stopped!");
7171
}
72-
_tasks.emplace(std::move(task));
72+
_tasks.push(std::move(task));
7373
}
7474
// Notify about a new task - one of the workers will pick it up
7575
_condition.notify_one();

0 commit comments

Comments
 (0)