From 89f647d521147eed571e126273ba2fe069c75f45 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Sun, 25 Nov 2018 17:18:12 -0800 Subject: [PATCH] Redefine hashcode for AttributedString Summary: This diff changes the method to calculate the hash of an AttributedString (removing shadowNode and parentShadowNode from it). This is necessary becuase otherwise hashcode of clonned parent keep changing in every state change, when the text doesnt change With this change we are able to cache spannables in android properly Reviewed By: shergin Differential Revision: D13189110 fbshipit-source-id: c1f7372809ce98a5b4d091485cc15281a4ab5e1e --- .../com/facebook/react/views/text/TextLayoutManager.java | 1 + ReactCommon/fabric/attributedstring/AttributedString.h | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java index f6b4581cd..010b2df58 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java @@ -164,6 +164,7 @@ public class TextLayoutManager { synchronized (sSpannableCacheLock) { preparedSpannableText = sSpannableCache.get(hash); + //TODO: T31905686 the hash does not guarantee equality of texts if (preparedSpannableText != null) { return preparedSpannableText; } diff --git a/ReactCommon/fabric/attributedstring/AttributedString.h b/ReactCommon/fabric/attributedstring/AttributedString.h index 16c975085..2dd66dd78 100644 --- a/ReactCommon/fabric/attributedstring/AttributedString.h +++ b/ReactCommon/fabric/attributedstring/AttributedString.h @@ -89,11 +89,7 @@ struct hash { size_t operator()( const facebook::react::AttributedString::Fragment &fragment) const { return std::hash{}(fragment.string) + - std::hash{}( - fragment.textAttributes) + - std::hash{}(fragment.shadowNode) + - std::hash{}( - fragment.parentShadowNode); + std::hash{}(fragment.textAttributes); } };