From 780d33c8a74b6b4c6a1ebdd338148daf2566d457 Mon Sep 17 00:00:00 2001 From: ram Date: Thu, 12 Dec 2024 10:05:11 +0000 Subject: [PATCH] Edit function call to support 32-bit and 64-bit str --- nac3core/irrt/irrt/string.hpp | 15 ++++++++------- nac3standalone/demo/src/str.py | 8 +------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/nac3core/irrt/irrt/string.hpp b/nac3core/irrt/irrt/string.hpp index 5fc3571..d873b9f 100644 --- a/nac3core/irrt/irrt/string.hpp +++ b/nac3core/irrt/irrt/string.hpp @@ -1,17 +1,14 @@ #pragma once #include "irrt/int_types.hpp" + namespace { template int32_t __nac3_str_eq_impl(const char* str1, SizeT len1, const char* str2, SizeT len2) { - if (str1 == str2) return 1; - if (len1 != len2) return 0; - for (SizeT i = 0; i < len1; ++i) { - if (static_cast(str1[i]) != static_cast(str2[i])) { - return 0; - } + if (len1 != len2){ + return 0; } - return 1; + return (__builtin_strncmp(str1, str2, static_cast(len1)) == 0) ? 1 : 0; } } // namespace @@ -19,4 +16,8 @@ extern "C" { int32_t nac3_str_eq(const char* str1, uint64_t len1, const char* str2, uint64_t len2) { return __nac3_str_eq_impl(str1, len1, str2, len2); } + +int32_t nac3_str_eq_i32(const char* str1, uint32_t len1, const char* str2, uint32_t len2) { + return __nac3_str_eq_impl(str1, len1, str2, len2); +} } \ No newline at end of file diff --git a/nac3standalone/demo/src/str.py b/nac3standalone/demo/src/str.py index 11632dc..d28f05e 100644 --- a/nac3standalone/demo/src/str.py +++ b/nac3standalone/demo/src/str.py @@ -11,9 +11,6 @@ def str_eq(): output_bool("a" == "a") output_bool("test string" == "test string") output_bool("test string1" == "test string2") - output_bool("test" == "testing") - output_bool("abcd" == "abdc") - output_bool(" " == " ") def str_ne(): @@ -24,13 +21,10 @@ def str_ne(): output_bool("a" != "a") output_bool("test string" != "test string") output_bool("test string1" != "test string2") - output_bool("test" != "testing") - output_bool("abcd" != "abdc") - output_bool(" " != " ") def run() -> int32: str_eq() str_ne() - return 0 \ No newline at end of file + return 0