aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsribee8 <145801438+sribee8@users.noreply.github.com>2025-06-16 11:03:21 -0700
committerGitHub <noreply@github.com>2025-06-16 18:03:21 +0000
commit4cd3e41bce449a10f431a3112b6cb8d7bc1b09cf (patch)
treed9a42dbd5133656eee55002ec4ef6e71be736c46
parent267b859fc60acda510027bd6139c54d660c6fb21 (diff)
downloadllvm-4cd3e41bce449a10f431a3112b6cb8d7bc1b09cf.zip
llvm-4cd3e41bce449a10f431a3112b6cb8d7bc1b09cf.tar.gz
llvm-4cd3e41bce449a10f431a3112b6cb8d7bc1b09cf.tar.bz2
[libc] Removed public function calls in table.h (#144168)
Removed strcmp, strlen, and memset calls from table.h and replaced them with internal functions. --------- Co-authored-by: Sriya Pratipati <sriyap@google.com>
-rw-r--r--libc/src/__support/HashTable/CMakeLists.txt5
-rw-r--r--libc/src/__support/HashTable/table.h15
-rw-r--r--libc/test/src/__support/HashTable/table_test.cpp4
3 files changed, 13 insertions, 11 deletions
diff --git a/libc/src/__support/HashTable/CMakeLists.txt b/libc/src/__support/HashTable/CMakeLists.txt
index 3c487e4..a1de068 100644
--- a/libc/src/__support/HashTable/CMakeLists.txt
+++ b/libc/src/__support/HashTable/CMakeLists.txt
@@ -32,9 +32,8 @@ add_header_library(
libc.src.__support.macros.attributes
libc.src.__support.macros.optimization
libc.src.__support.memory_size
- libc.src.string.memset
- libc.src.string.strcmp
- libc.src.string.strlen
+ libc.src.string.memory_utils.inline_strcmp
+ libc.src.string.string_utils
)
add_header_library(
diff --git a/libc/src/__support/HashTable/table.h b/libc/src/__support/HashTable/table.h
index 13badb9..10dd971 100644
--- a/libc/src/__support/HashTable/table.h
+++ b/libc/src/__support/HashTable/table.h
@@ -18,9 +18,8 @@
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h"
#include "src/__support/memory_size.h"
-#include "src/string/memset.h"
-#include "src/string/strcmp.h"
-#include "src/string/strlen.h"
+#include "src/string/memory_utils/inline_strcmp.h"
+#include "src/string/string_utils.h"
#include <stddef.h>
#include <stdint.h>
@@ -158,7 +157,9 @@ private:
for (size_t i : masks) {
size_t index = (pos + i) & entries_mask;
ENTRY &entry = this->entry(index);
- if (LIBC_LIKELY(entry.key != nullptr && strcmp(entry.key, key) == 0))
+ auto comp = [](char l, char r) -> int { return l - r; };
+ if (LIBC_LIKELY(entry.key != nullptr &&
+ inline_strcmp(entry.key, key, comp) == 0))
return index;
}
BitMask available = ctrls.mask_available();
@@ -176,7 +177,7 @@ private:
LIBC_INLINE uint64_t oneshot_hash(const char *key) const {
LIBC_NAMESPACE::internal::HashState hasher = state;
- hasher.update(key, strlen(key));
+ hasher.update(key, internal::string_length(key));
return hasher.finish();
}
@@ -282,8 +283,8 @@ public:
table->entries_mask = entries - 1u;
table->available_slots = entries / 8 * 7;
table->state = HashState{randomness};
- memset(&table->control(0), 0x80, ctrl_sizes);
- memset(mem, 0, table->offset_from_entries());
+ __builtin_memset(&table->control(0), 0x80, ctrl_sizes);
+ __builtin_memset(mem, 0, table->offset_from_entries());
}
return table;
}
diff --git a/libc/test/src/__support/HashTable/table_test.cpp b/libc/test/src/__support/HashTable/table_test.cpp
index a579bfa..ba9849b 100644
--- a/libc/test/src/__support/HashTable/table_test.cpp
+++ b/libc/test/src/__support/HashTable/table_test.cpp
@@ -108,7 +108,9 @@ TEST(LlvmLibcTableTest, Insertion) {
static_cast<void *>(keys[CAP].bytes));
for (size_t i = 0; i <= CAP; ++i) {
- ASSERT_EQ(strcmp(table->find(keys[i].bytes)->key, keys[i].bytes), 0);
+ auto comp = [](char l, char r) -> int { return l - r; };
+ ASSERT_EQ(
+ inline_strcmp(table->find(keys[i].bytes)->key, keys[i].bytes, comp), 0);
}
for (size_t i = CAP + 1; i < 256; ++i) {
ASSERT_EQ(table->find(keys[i].bytes), static_cast<ENTRY *>(nullptr));