Fabric: ComponentDescriptorRegistry::operator[] marked as const

Summary:
Quite trivial.
Note that std::unordered_map's `operator[]` is not `const`, so we have to use `at` instead.

Reviewed By: mdvacca

Differential Revision: D7467799

fbshipit-source-id: df38b21dccee4b347f7c070600af0d52f38d6570
This commit is contained in:
Valentin Shergin 2018-04-10 12:46:01 -07:00 committed by Facebook Github Bot
parent b2af59a0f0
commit 5463fc260b
2 changed files with 10 additions and 6 deletions

View File

@ -13,13 +13,13 @@ void ComponentDescriptorRegistry::registerComponentDescriptor(SharedComponentDes
_registryByName[componentName] = componentDescriptor;
}
const SharedComponentDescriptor ComponentDescriptorRegistry::operator[](const SharedShadowNode &shadowNode) {
const SharedComponentDescriptor ComponentDescriptorRegistry::operator[](const SharedShadowNode &shadowNode) const {
ComponentHandle componentHandle = shadowNode->getComponentHandle();
return _registryByHandle[componentHandle];
return _registryByHandle.at(componentHandle);
}
const SharedComponentDescriptor ComponentDescriptorRegistry::operator[](const ComponentName &componentName) {
return _registryByName[componentName];
const SharedComponentDescriptor ComponentDescriptorRegistry::operator[](const ComponentName &componentName) const {
return _registryByName.at(componentName);
}
} // namespace react

View File

@ -9,6 +9,10 @@
namespace facebook {
namespace react {
class ComponentDescriptorRegistry;
using SharedComponentDescriptorRegistry = std::shared_ptr<const ComponentDescriptorRegistry>;
/*
* Registry of particular `ComponentDescriptor`s.
*/
@ -17,8 +21,8 @@ class ComponentDescriptorRegistry {
public:
void registerComponentDescriptor(SharedComponentDescriptor componentDescriptor);
const SharedComponentDescriptor operator[](const SharedShadowNode &shadowNode);
const SharedComponentDescriptor operator[](const ComponentName &componentName);
const SharedComponentDescriptor operator[](const SharedShadowNode &shadowNode) const;
const SharedComponentDescriptor operator[](const ComponentName &componentName) const;
private:
std::unordered_map<ComponentHandle, SharedComponentDescriptor> _registryByHandle;