From 7addae7d682b443c7c9442428f3cada728e83389 Mon Sep 17 00:00:00 2001 From: German Tretiakov Date: Wed, 10 Sep 2025 08:55:37 +0000 Subject: [PATCH] Acceleration of string comparison Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICXDK1 Signed-off-by: German Tretiakov --- static_core/irtoc/scripts/string_helpers.irt | 10 ++++++++++ static_core/plugins/ets/stdlib/std/core/Runtime.ets | 2 ++ 2 files changed, 12 insertions(+) diff --git a/static_core/irtoc/scripts/string_helpers.irt b/static_core/irtoc/scripts/string_helpers.irt index c3663a7663..0dcddf8304 100644 --- a/static_core/irtoc/scripts/string_helpers.irt +++ b/static_core/irtoc/scripts/string_helpers.irt @@ -173,6 +173,16 @@ def GenerateStringEquals(lang, dynamic, compression, cgmode = :FastPath) Return(res).b Label(:Long) + hashcode1 := LoadI(str1).Imm(Constants::STRING_HASHCODE_OFFSET).u32 + If(hashcode1, 0).NE.b { + hashcode2 := LoadI(str2).Imm(Constants::STRING_HASHCODE_OFFSET).u32 + If(hashcode2, 0).NE.b { + If(hashcode1, hashcode2).NE.b { + Goto(:NotEqual) + } + } + } + unroll := Compare(length, 64).GE.b IfImm(unroll).Imm(0).SrcType("DataType::BOOL").NE.b { if cgmode == :NativePlus diff --git a/static_core/plugins/ets/stdlib/std/core/Runtime.ets b/static_core/plugins/ets/stdlib/std/core/Runtime.ets index 63bcf5fcdb..0cac6ec148 100644 --- a/static_core/plugins/ets/stdlib/std/core/Runtime.ets +++ b/static_core/plugins/ets/stdlib/std/core/Runtime.ets @@ -60,6 +60,8 @@ export final class Runtime { if (o1 instanceof Number && o2 instanceof Number) { return Runtime.sameNumberValue(o1 as Number, o2 as Number) + } else if (o1 instanceof String && o2 instanceof String) { + return (o1 as String).equals(o2) // same semantics as ==, but faster } else if (o1 instanceof Float && o2 instanceof Float) { return Runtime.sameFloatValue(o1 as Float, o2 as Float) } -- Gitee