From b41307af77e23caedd42cfc377377ac9d3cc25cb Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 2 Mar 2020 23:00:34 -0800 Subject: [PATCH] Fabric: Small improvements in Differentiator/TinyMap Summary: What's changed: * `end()` now returns the pointer to the imaginary element after the very last one (which is aligned with STL); * `erase()` now swaps the removing and the last elements and shrinks the size of an array. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D19965405 fbshipit-source-id: 92eedf38d55be35a0d9ab6120634b51c8d6e4674 --- ReactCommon/fabric/mounting/Differentiator.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ReactCommon/fabric/mounting/Differentiator.cpp b/ReactCommon/fabric/mounting/Differentiator.cpp index 05e1cd8f5f4..4d327419224 100644 --- a/ReactCommon/fabric/mounting/Differentiator.cpp +++ b/ReactCommon/fabric/mounting/Differentiator.cpp @@ -45,11 +45,11 @@ class TinyMap final { using Iterator = Pair *; inline Iterator begin() { - return (Pair *)vector_; + return &vector_.front(); } inline Iterator end() { - return nullptr; + return &vector_.back() + 1; } inline Iterator find(KeyT key) { @@ -68,11 +68,8 @@ class TinyMap final { } inline void erase(Iterator iterator) { - static_assert( - std::is_same::value, - "The collection is designed to store only `Tag`s as keys."); - // Zero is a invalid tag. - iterator->first = 0; + *iterator = vector_.at(vector_.size() - 1); + vector_.pop_back(); } private: