Skip to content

Commit 098275f

Browse files
committed
[stdlib] Clean up Set and Dictionary
- Use _HashTable to unify low-level hashing operations across Set and Dictionary. - Store the capacity directly inside the storage header. This allows the maximum load factor to be controlled by non-inlinable code. - Introduce a dedicated class for the empty singleton. - Add _BridgingHashBuffer, a standalone flat hash buffer for use in deferred bridging. Use it to eliminate the need to support non-hashable storage/wrapper variants and to improve memory use in cases where Key or Value are verbatim bridged. - Eliminate the “TypedNative*Storage” class and _NativeSet/_NativeDictionary’s support for non-hashable keys. - Rename storage classes as follows: _RawNativeSetStorage ⟹ _RawSetStorage _RawNativeDictionaryStorage ⟹ _RawDictionaryStorage _TypedNativeSetStorage ⟹ (removed) _TypedNativeDictionaryStorage ⟹ (removed) _HashableTypedNativeSetStorage ⟹ _SetStorage _HashableTypedNativeDictionaryStorage ⟹ _DictionaryStorage The new names make it obvious which ivar layout is in use.
1 parent 86f64f5 commit 098275f

File tree

6 files changed

+2223
-2831
lines changed

6 files changed

+2223
-2831
lines changed

stdlib/public/SwiftShims/GlobalObjects.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,36 +40,33 @@ struct _SwiftEmptyArrayStorage {
4040
SWIFT_RUNTIME_STDLIB_API
4141
struct _SwiftEmptyArrayStorage _swiftEmptyArrayStorage;
4242

43-
struct _SwiftUnsafeBitMap {
44-
__swift_uintptr_t *values;
45-
__swift_intptr_t bitCount;
46-
};
47-
4843
struct _SwiftDictionaryBodyStorage {
49-
__swift_intptr_t capacity;
5044
__swift_intptr_t count;
51-
struct _SwiftUnsafeBitMap initializedEntries;
52-
void *keys;
53-
void *values;
45+
__swift_intptr_t capacity;
46+
__swift_intptr_t scale;
47+
__swift_uint64_t seed;
48+
void *rawKeys;
49+
void *rawValues;
5450
};
5551

5652
struct _SwiftSetBodyStorage {
57-
__swift_intptr_t capacity;
5853
__swift_intptr_t count;
59-
struct _SwiftUnsafeBitMap initializedEntries;
60-
void *keys;
54+
__swift_intptr_t capacity;
55+
__swift_intptr_t scale;
56+
__swift_uint64_t seed;
57+
void *rawElements;
6158
};
6259

6360
struct _SwiftEmptyDictionarySingleton {
6461
struct HeapObject header;
6562
struct _SwiftDictionaryBodyStorage body;
66-
__swift_uintptr_t entries;
63+
__swift_uint64_t metadata;
6764
};
6865

6966
struct _SwiftEmptySetSingleton {
7067
struct HeapObject header;
7168
struct _SwiftSetBodyStorage body;
72-
__swift_uintptr_t entries;
69+
__swift_uint64_t metadata;
7370
};
7471

7572
SWIFT_RUNTIME_STDLIB_API

0 commit comments

Comments
 (0)