Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions library/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3317,8 +3317,10 @@ def __gt__(self, other):

__hash__ = None

def __init__(self, other=_Unbound, /, **kwargs):
dict.update(self, other, **kwargs)
# def __init__(self, other=_Unbound, /, **kwargs):
# if _dict_update(self, other, kwargs) is not _Unbound:
# return
# dict.update(self, other, **kwargs)

def __iter__(self):
_builtin()
Expand Down Expand Up @@ -3351,9 +3353,8 @@ def clear(self):
_builtin()

def copy(self):
_dict_guard(self)
result = {}
result.update(self)
_dict_update(result, self, result)
return result

@_classmethod
Expand Down Expand Up @@ -3405,6 +3406,8 @@ def update(self, iterable=_Unbound, /, **kwargs):
for key, value in kwargs.items():
_dict_setitem(self, key, value)

__init__ = update

def values(self):
_builtin()

Expand Down
17 changes: 10 additions & 7 deletions runtime/dict-builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,7 @@ static void dictInsertNoUpdate(const MutableTuple& data,
}
}

static void dictEnsureCapacity(Thread* thread, const Dict& dict) {
DCHECK(dict.numIndices() && Utils::isPowerOfTwo(dict.numIndices()),
"dict capacity must be power of two, greater than zero");
if (dictHasUsableItem(dict)) {
return;
}

static NEVER_INLINE void dictGrow(Thread* thread, const Dict& dict) {
// TODO(T44247845): Handle overflow here.
word new_num_indices = dict.numIndices() * kDictGrowthFactor;
DCHECK(new_num_indices < kTombstoneValue,
Expand Down Expand Up @@ -361,6 +355,15 @@ static void dictEnsureCapacity(Thread* thread, const Dict& dict) {
dict.setFirstEmptyItemIndex(dict.numItems() * kItemNumPointers);
}

static void dictEnsureCapacity(Thread* thread, const Dict& dict) {
DCHECK(dict.numIndices() && Utils::isPowerOfTwo(dict.numIndices()),
"dict capacity must be power of two, greater than zero");
if (dictHasUsableItem(dict)) {
return;
}
dictGrow(thread, dict);
}

RawObject dictAtPut(Thread* thread, const Dict& dict, const Object& key,
word hash, const Object& value) {
if (dict.indices() == SmallInt::fromWord(0)) {
Expand Down