From 5463fc260b8d703f9da34e6be5f83d1079e4302a Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 10 Apr 2018 12:46:01 -0700 Subject: [PATCH] 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 --- .../fabric/uimanager/ComponentDescriptorRegistry.cpp | 8 ++++---- .../fabric/uimanager/ComponentDescriptorRegistry.h | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.cpp b/ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.cpp index d209f590c..298e6c999 100644 --- a/ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.cpp +++ b/ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.cpp @@ -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 diff --git a/ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.h b/ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.h index 462ab9f7f..57d03d524 100644 --- a/ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.h +++ b/ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.h @@ -9,6 +9,10 @@ namespace facebook { namespace react { +class ComponentDescriptorRegistry; + +using SharedComponentDescriptorRegistry = std::shared_ptr; + /* * 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 _registryByHandle;