Loading...
--- dyld/dyld-1235.2/common/PerfectHash.cpp
+++ dyld/dyld-955/common/PerfectHash.cpp
@@ -40,17 +40,10 @@
------------------------------------------------------------------------------
*/
-#include <TargetConditionals.h>
-
-#if !TARGET_OS_EXCLAVEKIT
-
-#include <strings.h>
#include "PerfectHash.h"
-#if BUILDING_CACHE_BUILDER || BUILDING_UNIT_TESTS || BUILDING_CACHE_BUILDER_UNIT_TESTS
+#if BUILDING_CACHE_BUILDER || BUILDING_UNIT_TESTS
#include <dispatch/dispatch.h>
-#include <string>
-#include <vector>
#endif
namespace objc {
@@ -183,8 +176,6 @@
return c;
}
-#if BUILDING_CACHE_BUILDER || BUILDING_UNIT_TESTS || BUILDING_CACHE_BUILDER_UNIT_TESTS
-
/*
------------------------------------------------------------------------------
This generates a minimal perfect hash function. That means, given a
@@ -380,6 +371,7 @@
// gencode *final; /* output, code for the final hash */
{
ub4 loga = log2u(alen); /* log based 2 of blen */
+#if BUILDING_CACHE_BUILDER || BUILDING_UNIT_TESTS
dispatch_apply(keys.count(), DISPATCH_APPLY_AUTO, ^(size_t index) {
ub4 i = (ub4)index;
key *mykey = &keys[i];
@@ -391,6 +383,15 @@
mykey->a_k = (loga > 0) ? (ub4)(hash >> (UB8BITS-loga)) : 0;
mykey->b_k = (blen > 1) ? (hash & (blen-1)) : 0;
});
+#else
+ for (size_t index = 0; index != keys.count(); ++index) {
+ ub4 i = (ub4)index;
+ key *mykey = &keys[i];
+ ub8 hash = lookup8(mykey->name_k, mykey->len_k, salt);
+ mykey->a_k = (loga > 0) ? (ub4)(hash >> (UB8BITS-loga)) : 0;
+ mykey->b_k = (blen > 1) ? (hash & (blen-1)) : 0;
+ };
+#endif
}
@@ -781,18 +782,20 @@
}
}
-void PerfectHash::make_perfect(const std::vector<ObjCString>& strings, objc::PerfectHash& phash)
+#if BUILDING_CACHE_BUILDER || BUILDING_UNIT_TESTS
+
+void PerfectHash::make_perfect(const string_map& strings, objc::PerfectHash& phash)
{
dyld3::OverflowSafeArray<key> keys;
/* read in the list of keywords */
keys.reserve(strings.size());
-
- for ( const ObjCString& stringAndOffset: strings ) {
- const std::string_view& str = stringAndOffset.first;
+ size_t i;
+ string_map::const_iterator s;
+ for (i = 0, s = strings.begin(); s != strings.end(); ++s, ++i) {
key mykey;
- mykey.name1_k = (ub1 *)str.data();
- mykey.len1_k = (ub4)str.size();
+ mykey.name1_k = (ub1 *)s->first;
+ mykey.len1_k = (ub4)strlen(s->first);
mykey.name2_k = (ub1 *)nullptr;
mykey.len2_k = (ub4)0;
keys.push_back(mykey);
@@ -801,8 +804,29 @@
make_perfect(keys, phash);
}
-#endif // BUILDING_CACHE_BUILDER || BUILDING_UNIT_TESTS || BUILDING_CACHE_BUILDER_UNIT_TESTS
+#endif
+
+void PerfectHash::make_perfect(const dyld3::OverflowSafeArray<const char*>& strings, objc::PerfectHash& phash)
+{
+ dyld3::OverflowSafeArray<key> keys;
+
+ /* read in the list of keywords */
+ keys.reserve(strings.count());
+ for (const char* s : strings) {
+ key mykey;
+#if BUILDING_CACHE_BUILDER || BUILDING_UNIT_TESTS
+ mykey.name1_k = (ub1 *)s;
+ mykey.len1_k = (ub4)strlen(s);
+ mykey.name2_k = (ub1 *)nullptr;
+ mykey.len2_k = (ub4)0;
+#else
+ mykey.name_k = (ub1 *)s;
+ mykey.len_k = (ub4)strlen(s);
+#endif
+ keys.push_back(mykey);
+ }
+
+ make_perfect(keys, phash);
+}
} // namespace objc
-
-#endif // !TARGET_OS_EXCLAVEKIT