From ea5c8dbe66c7c5a93b70e4b0a6d9f6cf950ec00b Mon Sep 17 00:00:00 2001 From: GrieferAtWork Date: Sun, 5 May 2024 21:36:36 +0200 Subject: [PATCH] Get rid of `DeeObject_GetItemDef` --- include/deemon/cached-dict.h | 3 - include/deemon/cxx/object.h | 163 +++- include/deemon/cxx/tuple.h | 10 +- include/deemon/dict.h | 12 - include/deemon/object.h | 9 +- src/deemon/execute/module.c | 16 +- .../link-deemon-gcc-i386-cygwin.def | 3 - .../link-deemon-msvc-i386-win32.def | 3 - src/deemon/objects/attribute.c | 2 +- src/deemon/objects/bytes.c | 4 +- src/deemon/objects/cached-dict.c | 48 +- src/deemon/objects/dict.c | 114 --- src/deemon/objects/map.c | 24 +- src/deemon/objects/object.c | 23 +- src/deemon/objects/seq.c | 10 +- src/deemon/objects/seq/bsearch-impl.c.inl | 4 +- src/deemon/objects/seq/concat.c | 8 +- src/deemon/objects/seq/default-iterators.c | 6 +- src/deemon/objects/seq/each.c | 14 +- src/deemon/objects/seq_functions.c | 46 +- src/deemon/runtime/attribute.c | 9 + src/deemon/runtime/notify.c | 2 +- src/deemon/runtime/operator.c | 699 ++++++++---------- src/dex/_hostasm/generator-vstack-ex.c | 30 +- src/dex/collections/rangemap.c | 11 +- 25 files changed, 586 insertions(+), 687 deletions(-) diff --git a/include/deemon/cached-dict.h b/include/deemon/cached-dict.h index e906358b2..e32b85b54 100644 --- a/include/deemon/cached-dict.h +++ b/include/deemon/cached-dict.h @@ -89,9 +89,6 @@ INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeCachedDict_GetItemNRStringLen INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeCachedDict_TryGetItemNR(DeeCachedDictObject *self, DeeObject *key); INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeCachedDict_TryGetItemNRStringHash(DeeCachedDictObject *self, char const *__restrict key, Dee_hash_t hash); INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeCachedDict_TryGetItemNRStringLenHash(DeeCachedDictObject *self, char const *__restrict key, size_t keylen, Dee_hash_t hash); -INTDEF WUNUSED NONNULL((1, 2, 3)) DeeObject *DCALL DeeCachedDict_GetItemNRDef(DeeCachedDictObject *self, DeeObject *key, DeeObject *def); -INTDEF WUNUSED NONNULL((1, 2, 4)) DeeObject *DCALL DeeCachedDict_GetItemNRStringHashDef(DeeCachedDictObject *self, char const *__restrict key, Dee_hash_t hash, DeeObject *def); -INTDEF WUNUSED NONNULL((1, 2, 5)) DeeObject *DCALL DeeCachedDict_GetItemNRStringLenHashDef(DeeCachedDictObject *self, char const *__restrict key, size_t keylen, Dee_hash_t hash, DeeObject *def); #endif /* CONFIG_BUILDING_DEEMON */ /* Hash iteration helpers. */ diff --git a/include/deemon/cxx/object.h b/include/deemon/cxx/object.h index e52978aa7..da5bc039f 100644 --- a/include/deemon/cxx/object.h +++ b/include/deemon/cxx/object.h @@ -1164,7 +1164,12 @@ class ConstGetAndSetRefProxyWithDefault using ConstGetAndSetRefProxy::operator=; template Ref get(S *def) const { - return inherit(((ProxyType const *)this)->_getref(def)); + DREF DeeObject *result = ((ProxyType const *)this)->_trygetref(); + if (result == ITER_DONE) { + result = (DREF DeeObject *)def; + Dee_Incref(result); + } + return inherit(result); } }; @@ -1927,8 +1932,8 @@ class ItemProxyObjBase { WUNUSED DREF DeeObject *_getref() const DEE_CXX_NOTHROW { return DeeObject_GetItem(m_ptr, m_idx); } - WUNUSED DREF DeeObject *_getref(DeeObject *def) const DEE_CXX_NOTHROW { - return DeeObject_GetItemDef(m_ptr, m_idx, def); + WUNUSED DREF DeeObject *_trygetref() const DEE_CXX_NOTHROW { + return DeeObject_TryGetItem(m_ptr, m_idx); } WUNUSED int _setref(DeeObject *value) const DEE_CXX_NOTHROW { return DeeObject_SetItem(m_ptr, m_idx, value); @@ -1958,14 +1963,8 @@ class ItemProxyIdxBase { WUNUSED DREF DeeObject *_getref() const DEE_CXX_NOTHROW { return DeeObject_GetItemIndex(m_ptr, m_idx); } - WUNUSED DREF DeeObject *_getref(DeeObject *def) const DEE_CXX_NOTHROW { - DREF DeeObject *index_ob, *result = NULL; - index_ob = DeeInt_NewSize(m_idx); - if likely(index_ob) { - result = DeeObject_GetItemDef(m_ptr, index_ob, def); - Dee_Decref(index_ob); - } - return result; + WUNUSED DREF DeeObject *_trygetref() const DEE_CXX_NOTHROW { + return DeeObject_TryGetItemIndex(m_ptr, m_idx); } WUNUSED int _setref(DeeObject *value) const DEE_CXX_NOTHROW { return DeeObject_SetItemIndex(m_ptr, m_idx, value); @@ -1998,8 +1997,8 @@ class ItemProxySthBase { WUNUSED DREF DeeObject *_getref() const DEE_CXX_NOTHROW { return DeeObject_GetItemStringHash(m_ptr, m_key, m_hsh); } - WUNUSED DREF DeeObject *_getref(DeeObject *def) const DEE_CXX_NOTHROW { - return DeeObject_GetItemStringHashDef(m_ptr, m_key, m_hsh, def); + WUNUSED DREF DeeObject *_trygetref() const DEE_CXX_NOTHROW { + return DeeObject_TryGetItemStringHash(m_ptr, m_key, m_hsh); } WUNUSED int _setref(DeeObject *value) const DEE_CXX_NOTHROW { return DeeObject_SetItemStringHash(m_ptr, m_key, m_hsh, value); @@ -2035,8 +2034,8 @@ class ItemProxySnhBase { WUNUSED DREF DeeObject *_getref() const DEE_CXX_NOTHROW { return DeeObject_GetItemStringLenHash(m_ptr, m_key, m_len, m_hsh); } - WUNUSED DREF DeeObject *_getref(DeeObject *def) const DEE_CXX_NOTHROW { - return DeeObject_GetItemStringLenHashDef(m_ptr, m_key, m_len, m_hsh, def); + WUNUSED DREF DeeObject *_trygetref(DeeObject *def) const DEE_CXX_NOTHROW { + return DeeObject_TryGetItemStringLenHash(m_ptr, m_key, m_len, m_hsh); } WUNUSED int _setref(DeeObject *value) const DEE_CXX_NOTHROW { return DeeObject_SetItemStringLenHash(m_ptr, m_key, m_len, m_hsh, value); @@ -2521,39 +2520,157 @@ class ItemProxyAccessor { return ItemProxySnh(((ProxyType *)this)->ptr(), key, keylen, hash); } + NONNULL_CXX((1)) DREF DeeObject *_getitem(DeeObject *index_or_key) { + return DeeObject_GetItem(((ProxyType *)this)->ptr(), index_or_key); + } + NONNULL_CXX((1)) DREF DeeObject *_getitem(size_t index) { + return DeeObject_GetItemIndex(((ProxyType *)this)->ptr(), index); + } + NONNULL_CXX((1)) DREF DeeObject *_getitem(char const *key) { + return DeeObject_GetItemString(((ProxyType *)this)->ptr(), key); + } + NONNULL_CXX((1)) DREF DeeObject *_getitem(char const *key, Dee_hash_t hash) { + return DeeObject_GetItemStringHash(((ProxyType *)this)->ptr(), key, hash); + } + NONNULL_CXX((1)) DREF DeeObject *_getitem(char const *key, size_t keylen, Dee_hash_t hash) { + return DeeObject_GetItemStringLenHash(((ProxyType *)this)->ptr(), key, keylen, hash); + } + + NONNULL_CXX((1)) DREF DeeObject *_trygetitem(DeeObject *index_or_key) { + return DeeObject_TryGetItem(((ProxyType *)this)->ptr(), index_or_key); + } + NONNULL_CXX((1)) DREF DeeObject *_trygetitem(size_t index) { + return DeeObject_TryGetItemIndex(((ProxyType *)this)->ptr(), index); + } + NONNULL_CXX((1)) DREF DeeObject *_trygetitem(char const *key) { + return DeeObject_TryGetItemString(((ProxyType *)this)->ptr(), key); + } + NONNULL_CXX((1)) DREF DeeObject *_trygetitem(char const *key, Dee_hash_t hash) { + return DeeObject_TryGetItemStringHash(((ProxyType *)this)->ptr(), key, hash); + } + NONNULL_CXX((1)) DREF DeeObject *_trygetitem(char const *key, size_t keylen, Dee_hash_t hash) { + return DeeObject_TryGetItemStringLenHash(((ProxyType *)this)->ptr(), key, keylen, hash); + } + + NONNULL_CXX((1)) int _bounditem(DeeObject *index_or_key) { + return DeeObject_BoundItem(((ProxyType *)this)->ptr(), index_or_key); + } + int _bounditem(size_t index) { + return DeeObject_BoundItemIndex(((ProxyType *)this)->ptr(), index); + } + NONNULL_CXX((1)) int _bounditem(char const *key) { + return DeeObject_BoundItemString(((ProxyType *)this)->ptr(), key); + } + NONNULL_CXX((1)) int _bounditem(char const *key, Dee_hash_t hash) { + return DeeObject_BoundItemStringHash(((ProxyType *)this)->ptr(), key, hash); + } + NONNULL_CXX((1)) int _bounditem(char const *key, size_t keylen, Dee_hash_t hash) { + return DeeObject_BoundItemStringLenHash(((ProxyType *)this)->ptr(), key, keylen, hash); + } + + NONNULL_CXX((1)) int _hasitem(DeeObject *index_or_key) { + return DeeObject_HasItem(((ProxyType *)this)->ptr(), index_or_key); + } + int _hasitem(size_t index) { + return DeeObject_HasItemIndex(((ProxyType *)this)->ptr(), index); + } + NONNULL_CXX((1)) int _hasitem(char const *key) { + return DeeObject_HasItemString(((ProxyType *)this)->ptr(), key); + } + NONNULL_CXX((1)) int _hasitem(char const *key, Dee_hash_t hash) { + return DeeObject_HasItemStringHash(((ProxyType *)this)->ptr(), key, hash); + } + NONNULL_CXX((1)) int _hasitem(char const *key, size_t keylen, Dee_hash_t hash) { + return DeeObject_HasItemStringLenHash(((ProxyType *)this)->ptr(), key, keylen, hash); + } + + NONNULL_CXX((1)) int _delitem(DeeObject *index_or_key) { + return DeeObject_DelItem(((ProxyType *)this)->ptr(), index_or_key); + } + int _delitem(size_t index) { + return DeeObject_DelItemIndex(((ProxyType *)this)->ptr(), index); + } + NONNULL_CXX((1)) int _delitem(char const *key) { + return DeeObject_DelItemString(((ProxyType *)this)->ptr(), key); + } + NONNULL_CXX((1)) int _delitem(char const *key, Dee_hash_t hash) { + return DeeObject_DelItemStringHash(((ProxyType *)this)->ptr(), key, hash); + } + NONNULL_CXX((1)) int _delitem(char const *key, size_t keylen, Dee_hash_t hash) { + return DeeObject_DelItemStringLenHash(((ProxyType *)this)->ptr(), key, keylen, hash); + } + + NONNULL_CXX((1, 2)) int _setitem(DeeObject *index_or_key, DeeObject *value) { + return DeeObject_SetItem(((ProxyType *)this)->ptr(), index_or_key, value); + } + NONNULL_CXX((2)) int _setitem(size_t index, DeeObject *value) { + return DeeObject_SetItemIndex(((ProxyType *)this)->ptr(), index, value); + } + NONNULL_CXX((1, 2)) int _setitem(char const *key, DeeObject *value) { + return DeeObject_SetItemString(((ProxyType *)this)->ptr(), key, value); + } + NONNULL_CXX((1, 3)) int _setitem(char const *key, Dee_hash_t hash, DeeObject *value) { + return DeeObject_SetItemStringHash(((ProxyType *)this)->ptr(), key, hash, value); + } + NONNULL_CXX((1, 4)) int _setitem(char const *key, size_t keylen, Dee_hash_t hash, DeeObject *value) { + return DeeObject_SetItemStringLenHash(((ProxyType *)this)->ptr(), key, keylen, hash, value); + } + + NONNULL_CXX((1)) Ref getitem(DeeObject *index_or_key) { return inherit(DeeObject_GetItem(((ProxyType *)this)->ptr(), index_or_key)); } NONNULL_CXX((1, 2)) Ref getitem(DeeObject *index_or_key, DeeObject *def) { - return inherit(DeeObject_GetItemDef(((ProxyType *)this)->ptr(), index_or_key, def)); + DREF DeeObject *result = DeeObject_TryGetItem(((ProxyType *)this)->ptr(), index_or_key); + if (result == ITER_DONE) { + Dee_Incref(def); + result = def; + } + return inherit(result); } Ref getitem(size_t index) { return inherit(DeeObject_GetItemIndex(((ProxyType *)this)->ptr(), index)); } NONNULL_CXX((2)) Ref getitem(size_t index, DeeObject *def) { - DREF DeeObject *index_ob, *result; - index_ob = throw_if_null(DeeInt_NewSize(index)); - result = DeeObject_GetItemDef(((ProxyType *)this)->ptr(), index_ob, def); - Dee_Decref(index_ob); + DREF DeeObject *result = DeeObject_TryGetItemIndex(((ProxyType *)this)->ptr(), index); + if (result == ITER_DONE) { + Dee_Incref(def); + result = def; + } return inherit(result); } NONNULL_CXX((1)) Ref getitem(char const *key) { return inherit(DeeObject_GetItemString(((ProxyType *)this)->ptr(), key)); } NONNULL_CXX((1, 2)) Ref getitem(char const *key, DeeObject *def) { - return inherit(DeeObject_GetItemStringDef(((ProxyType *)this)->ptr(), key, def)); + DREF DeeObject *result = DeeObject_TryGetItemString(((ProxyType *)this)->ptr(), key); + if (result == ITER_DONE) { + Dee_Incref(def); + result = def; + } + return inherit(result); } NONNULL_CXX((1)) Ref getitem(char const *key, Dee_hash_t hash) { return inherit(DeeObject_GetItemStringHash(((ProxyType *)this)->ptr(), key, hash)); } NONNULL_CXX((1, 3)) Ref getitem(char const *key, Dee_hash_t hash, DeeObject *def) { - return inherit(DeeObject_GetItemStringHashDef(((ProxyType *)this)->ptr(), key, hash, def)); + DREF DeeObject *result = DeeObject_TryGetItemStringHash(((ProxyType *)this)->ptr(), key, hash); + if (result == ITER_DONE) { + Dee_Incref(def); + result = def; + } + return inherit(result); } NONNULL_CXX((1)) Ref getitem(char const *key, size_t keylen, Dee_hash_t hash) { return inherit(DeeObject_GetItemStringLenHash(((ProxyType *)this)->ptr(), key, keylen, hash)); } NONNULL_CXX((1, 4)) Ref getitem(char const *key, size_t keylen, Dee_hash_t hash, DeeObject *def) { - return inherit(DeeObject_GetItemStringLenHashDef(((ProxyType *)this)->ptr(), key, keylen, hash, def)); + DREF DeeObject *result = DeeObject_TryGetItemStringLenHash(((ProxyType *)this)->ptr(), key, keylen, hash); + if (result == ITER_DONE) { + Dee_Incref(def); + result = def; + } + return inherit(result); } NONNULL_CXX((1)) bool bounditem(DeeObject *index_or_key) { diff --git a/include/deemon/cxx/tuple.h b/include/deemon/cxx/tuple.h index 7fced0f14..5dd9b856f 100644 --- a/include/deemon/cxx/tuple.h +++ b/include/deemon/cxx/tuple.h @@ -61,14 +61,8 @@ class _AbstractTupleItemWrapper WUNUSED DREF DeeObject *_getref() const DEE_CXX_NOTHROW { return DeeObject_GetItemIndex(m_self, Index); } - WUNUSED DREF DeeObject *_getref(DeeObject *def) const DEE_CXX_NOTHROW { - DREF DeeObject *index_ob, *result = NULL; - index_ob = DeeInt_NewSize(Index); - if likely(index_ob) { - result = DeeObject_GetItemDef(m_self, index_ob, def); - Dee_Decref(index_ob); - } - return result; + WUNUSED DREF DeeObject *_trygetref() const DEE_CXX_NOTHROW { + return DeeObject_TryGetItemIndex(m_self, Index); } WUNUSED int _setref(DeeObject *value) const DEE_CXX_NOTHROW { return DeeObject_SetItemIndex(m_self, Index, value); diff --git a/include/deemon/dict.h b/include/deemon/dict.h index 31c4ffede..d74dcfb13 100644 --- a/include/deemon/dict.h +++ b/include/deemon/dict.h @@ -108,11 +108,7 @@ DFUNDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL DeeDict_FromRoDict(DeeObject #ifdef CONFIG_BUILDING_DEEMON INTDEF WUNUSED NONNULL((1, 2, 3)) DREF DeeObject *DCALL DeeDict_GetItemDef(DeeObject *self, DeeObject *key, DeeObject *def); INTDEF WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL DeeDict_GetItemStringHash(DeeObject *__restrict self, char const *__restrict key, Dee_hash_t hash); -INTDEF WUNUSED NONNULL((1, 2, 4)) DREF DeeObject *DCALL DeeDict_GetItemStringHashDef(DeeObject *self, char const *__restrict key, Dee_hash_t hash, DeeObject *def); INTDEF WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL DeeDict_GetItemStringLenHash(DeeObject *__restrict self, char const *__restrict key, size_t keylen, Dee_hash_t hash); -INTDEF WUNUSED NONNULL((1, 2, 5)) DREF DeeObject *DCALL DeeDict_GetItemStringLenHashDef(DeeObject *self, char const *__restrict key, size_t keylen, Dee_hash_t hash, DeeObject *def); -INTDEF WUNUSED NONNULL((1, 2)) bool DCALL DeeDict_HasItemStringHash(DeeObject *__restrict self, char const *__restrict key, Dee_hash_t hash); -INTDEF WUNUSED NONNULL((1, 2)) bool DCALL DeeDict_HasItemStringLenHash(DeeObject *__restrict self, char const *__restrict key, size_t keylen, Dee_hash_t hash); INTDEF WUNUSED NONNULL((1, 2)) int DCALL DeeDict_DelItemStringHash(DeeObject *__restrict self, char const *__restrict key, Dee_hash_t hash); INTDEF WUNUSED NONNULL((1, 2)) int DCALL DeeDict_DelItemStringLenHash(DeeObject *__restrict self, char const *__restrict key, size_t keylen, Dee_hash_t hash); INTDEF WUNUSED NONNULL((1, 2, 4)) int DCALL DeeDict_SetItemStringHash(DeeObject *self, char const *__restrict key, Dee_hash_t hash, DeeObject *value); @@ -121,11 +117,7 @@ INTDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL DeeDict_ByHash(DeeObject *__re #else /* CONFIG_BUILDING_DEEMON */ #define DeeDict_GetItemDef(self, key, def) ((*DeeDict_Type.tp_seq->tp_nsi->nsi_maplike.nsi_getdefault)(self, key, def)) #define DeeDict_GetItemStringHash(self, key, hash) DeeObject_GetItemStringHash(self, key, hash) -#define DeeDict_GetItemStringHashDef(self, key, hash, def) DeeObject_GetItemStringHashDef(self, key, hash, def) #define DeeDict_GetItemStringLenHash(self, key, keylen, hash) DeeObject_GetItemStringLenHash(self, key, keylen, hash) -#define DeeDict_GetItemStringLenHashDef(self, key, keylen, hash, def) DeeObject_GetItemStringLenHashDef(self, key, keylen, hash, def) -#define DeeDict_HasItemStringHash(self, key, hash) DeeObject_HasItemStringHash(self, key, hash) -#define DeeDict_HasItemStringLenHash(self, key, keylen, hash) DeeObject_HasItemStringLenHash(self, key, keylen, hash) #define DeeDict_DelItemStringHash(self, key, hash) DeeObject_DelItemStringHash(self, key, hash) #define DeeDict_DelItemStringLenHash(self, key, keylen, hash) DeeObject_DelItemStringLenHash(self, key, keylen, hash) #define DeeDict_SetItemStringHash(self, key, hash, value) DeeObject_SetItemStringHash(self, key, hash, value) @@ -133,10 +125,6 @@ INTDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL DeeDict_ByHash(DeeObject *__re #endif /* !CONFIG_BUILDING_DEEMON */ #define DeeDict_GetItemString(self, key) DeeDict_GetItemStringHash(self, key, Dee_HashStr(key)) #define DeeDict_GetItemStringLen(self, key, keylen) DeeDict_GetItemStringLenHash(self, key, keylen, Dee_HashPtr(key, keylen)) -#define DeeDict_GetItemStringDef(self, key, def) DeeDict_GetItemStringHashDef(self, key, Dee_HashStr(key), def) -#define DeeDict_GetItemStringLenDef(self, key, keylen, def) DeeDict_GetItemStringLenHashDef(self, key, keylen, Dee_HashPtr(key, keylen), def) -#define DeeDict_HasItemString(self, key) DeeDict_HasItemStringHash(self, key, Dee_HashStr(key)) -#define DeeDict_HasItemStringLen(self, key, keylen) DeeDict_HasItemStringLenHash(self, key, keylen, Dee_HashPtr(key, keylen)) #define DeeDict_DelItemString(self, key) DeeDict_DelItemStringHash(self, key, Dee_HashStr(key)) #define DeeDict_DelItemStringLen(self, key, keylen) DeeDict_DelItemStringLenHash(self, key, keylen, Dee_HashPtr(key, keylen)) #define DeeDict_SetItemString(self, key, value) DeeDict_SetItemStringHash(self, key, Dee_HashStr(key), value) diff --git a/include/deemon/object.h b/include/deemon/object.h index ef800981d..10a6311f5 100644 --- a/include/deemon/object.h +++ b/include/deemon/object.h @@ -4658,18 +4658,13 @@ DFUNDEF WUNUSED NONNULL((1, 4)) int (DCALL DeeObject_SetRangeIndex)(DeeObject *s DFUNDEF WUNUSED NONNULL((1, 3)) int (DCALL DeeObject_SetRangeIndexN)(DeeObject *self, Dee_ssize_t begin, DeeObject *values); #define DeeObject_GetItemString(self, key) DeeObject_GetItemStringHash(self, key, Dee_HashStr(key)) #define DeeObject_GetItemStringLen(self, key, keylen) DeeObject_GetItemStringLenHash(self, key, keylen, Dee_HashPtr(key, keylen)) -#define DeeObject_GetItemStringDef(self, key, def) DeeObject_GetItemStringHashDef(self, key, Dee_HashStr(key), def) -#define DeeObject_GetItemStringLenDef(self, key, keylen, def) DeeObject_GetItemStringLenHashDef(self, key, keylen, Dee_HashPtr(key, keylen), def) +#define DeeObject_TryGetItemString(self, key) DeeObject_TryGetItemStringHash(self, key, Dee_HashStr(key)) +#define DeeObject_TryGetItemStringLen(self, key, keylen) DeeObject_TryGetItemStringLenHash(self, key, keylen, Dee_HashPtr(key, keylen)) #define DeeObject_DelItemString(self, key) DeeObject_DelItemStringHash(self, key, Dee_HashStr(key)) #define DeeObject_DelItemStringLen(self, key, keylen) DeeObject_DelItemStringLenHash(self, key, keylen, Dee_HashPtr(key, keylen)) #define DeeObject_SetItemString(self, key, value) DeeObject_SetItemStringHash(self, key, Dee_HashStr(key), value) #define DeeObject_SetItemStringLen(self, key, keylen, value) DeeObject_SetItemStringLenHash(self, key, keylen, Dee_HashPtr(key, keylen), value) -/* TODO: These are deprecated in favor of "DeeObject_TryGetItem()" */ -DFUNDEF WUNUSED NONNULL((1, 2, 3)) DREF DeeObject *(DCALL DeeObject_GetItemDef)(DeeObject *self, DeeObject *key, DeeObject *def); -DFUNDEF WUNUSED NONNULL((1, 2, 4)) DREF DeeObject *(DCALL DeeObject_GetItemStringHashDef)(DeeObject *self, char const *__restrict key, Dee_hash_t hash, DeeObject *def); -DFUNDEF WUNUSED NONNULL((1, 2, 5)) DREF DeeObject *(DCALL DeeObject_GetItemStringLenHashDef)(DeeObject *self, char const *__restrict key, size_t keylen, Dee_hash_t hash, DeeObject *def); - /* Check if a given item exists (`deemon.hasitem(self, index)') * @return: 0: Doesn't exist; * @return: 1: Does exists; diff --git a/src/deemon/execute/module.c b/src/deemon/execute/module.c index 42448bf20..8b60da121 100644 --- a/src/deemon/execute/module.c +++ b/src/deemon/execute/module.c @@ -370,7 +370,7 @@ DeeModule_BoundAttrSymbol(DeeModuleObject *__restrict self, goto read_symbol; } -LOCAL WUNUSED DREF DeeObject *DCALL +LOCAL WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL module_getattr_impl(DeeModuleObject *__restrict self, char const *__restrict attr_name, dhash_t hash) { dhash_t i, perturb; @@ -394,7 +394,7 @@ module_getattr_impl(DeeModuleObject *__restrict self, return NULL; } -LOCAL WUNUSED DREF DeeObject *DCALL +LOCAL WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL module_getattr_len_impl(DeeModuleObject *__restrict self, char const *__restrict attr_name, size_t attrlen, dhash_t hash) { @@ -421,7 +421,7 @@ module_getattr_len_impl(DeeModuleObject *__restrict self, return NULL; } -LOCAL int DCALL +LOCAL WUNUSED NONNULL((1, 2)) int DCALL module_boundattr_impl(DeeModuleObject *__restrict self, char const *__restrict attr_name, dhash_t hash) { dhash_t i, perturb; @@ -440,7 +440,7 @@ module_boundattr_impl(DeeModuleObject *__restrict self, return DeeObject_GenericBoundAttrStringHash((DeeObject *)self, attr_name, hash); } -LOCAL int DCALL +LOCAL WUNUSED NONNULL((1, 2)) int DCALL module_boundattr_len_impl(DeeModuleObject *__restrict self, char const *__restrict attr_name, size_t attrlen, dhash_t hash) { @@ -462,7 +462,7 @@ module_boundattr_len_impl(DeeModuleObject *__restrict self, return DeeObject_GenericBoundAttrStringLenHash((DeeObject *)self, attr_name, attrlen, hash); } -LOCAL bool DCALL +LOCAL WUNUSED NONNULL((1, 2)) bool DCALL module_hasattr_impl(DeeModuleObject *__restrict self, char const *__restrict attr_name, dhash_t hash) { dhash_t i, perturb; @@ -480,7 +480,7 @@ module_hasattr_impl(DeeModuleObject *__restrict self, return DeeObject_GenericHasAttrStringHash((DeeObject *)self, attr_name, hash); } -LOCAL bool DCALL +LOCAL WUNUSED NONNULL((1, 2)) bool DCALL module_hasattr_len_impl(DeeModuleObject *__restrict self, char const *__restrict attr_name, size_t attrlen, dhash_t hash) { @@ -541,7 +541,7 @@ DeeModule_DelAttrSymbol(DeeModuleObject *__restrict self, return 0; } -LOCAL int DCALL +LOCAL WUNUSED NONNULL((1, 2)) int DCALL module_delattr_impl(DeeModuleObject *__restrict self, char const *__restrict attr_name, dhash_t hash) { int error; @@ -564,7 +564,7 @@ module_delattr_impl(DeeModuleObject *__restrict self, return err_module_no_such_global_string(self, attr_name, ATTR_ACCESS_DEL); } -LOCAL int DCALL +LOCAL WUNUSED NONNULL((1, 2)) int DCALL module_delattr_len_impl(DeeModuleObject *__restrict self, char const *__restrict attr_name, size_t attrlen, dhash_t hash) { diff --git a/src/deemon/linker-scripts/link-deemon-gcc-i386-cygwin.def b/src/deemon/linker-scripts/link-deemon-gcc-i386-cygwin.def index cc0d9e037..72b94de98 100644 --- a/src/deemon/linker-scripts/link-deemon-gcc-i386-cygwin.def +++ b/src/deemon/linker-scripts/link-deemon-gcc-i386-cygwin.def @@ -660,12 +660,9 @@ EXPORTS _DeeObject_GetAttrStringLenHash@16=DeeObject_GetAttrStringLenHash@16 _DeeObject_GetBuf@12=DeeObject_GetBuf@12 _DeeObject_GetItem@8=DeeObject_GetItem@8 - _DeeObject_GetItemDef@12=DeeObject_GetItemDef@12 _DeeObject_GetItemIndex@8=DeeObject_GetItemIndex@8 _DeeObject_GetItemStringHash@12=DeeObject_GetItemStringHash@12 - _DeeObject_GetItemStringHashDef@16=DeeObject_GetItemStringHashDef@16 _DeeObject_GetItemStringLenHash@16=DeeObject_GetItemStringLenHash@16 - _DeeObject_GetItemStringLenHashDef@20=DeeObject_GetItemStringLenHashDef@20 _DeeObject_GetRange@12=DeeObject_GetRange@12 _DeeObject_GetRangeBeginIndex@12=DeeObject_GetRangeBeginIndex@12 _DeeObject_GetRangeEndIndex@12=DeeObject_GetRangeEndIndex@12 diff --git a/src/deemon/linker-scripts/link-deemon-msvc-i386-win32.def b/src/deemon/linker-scripts/link-deemon-msvc-i386-win32.def index b2dd8fe66..525799676 100644 --- a/src/deemon/linker-scripts/link-deemon-msvc-i386-win32.def +++ b/src/deemon/linker-scripts/link-deemon-msvc-i386-win32.def @@ -660,12 +660,9 @@ EXPORTS DeeObject_GetAttrStringLenHash@16=_DeeObject_GetAttrStringLenHash@16 DeeObject_GetBuf@12=_DeeObject_GetBuf@12 DeeObject_GetItem@8=_DeeObject_GetItem@8 - DeeObject_GetItemDef@12=_DeeObject_GetItemDef@12 DeeObject_GetItemIndex@8=_DeeObject_GetItemIndex@8 DeeObject_GetItemStringHash@12=_DeeObject_GetItemStringHash@12 - DeeObject_GetItemStringHashDef@16=_DeeObject_GetItemStringHashDef@16 DeeObject_GetItemStringLenHash@16=_DeeObject_GetItemStringLenHash@16 - DeeObject_GetItemStringLenHashDef@20=_DeeObject_GetItemStringLenHashDef@20 DeeObject_GetRange@12=_DeeObject_GetRange@12 DeeObject_GetRangeBeginIndex@12=_DeeObject_GetRangeBeginIndex@12 DeeObject_GetRangeEndIndex@12=_DeeObject_GetRangeEndIndex@12 diff --git a/src/deemon/objects/attribute.c b/src/deemon/objects/attribute.c index 342b01c0e..67d3919ed 100644 --- a/src/deemon/objects/attribute.c +++ b/src/deemon/objects/attribute.c @@ -1051,7 +1051,7 @@ enumattriter_visit(EnumAttrIter *__restrict self, dvisit_t proc, void *arg) { #ifdef CONFIG_LONGJMP_ENUMATTR -PRIVATE dssize_t DCALL +PRIVATE WUNUSED NONNULL((1, 2, 6)) dssize_t DCALL enumattr_longjmp(DeeObject *__restrict declarator, char const *__restrict attr_name, char const *attr_doc, uint16_t perm, DeeTypeObject *attr_type, diff --git a/src/deemon/objects/bytes.c b/src/deemon/objects/bytes.c index e9b523564..d47504da2 100644 --- a/src/deemon/objects/bytes.c +++ b/src/deemon/objects/bytes.c @@ -949,9 +949,9 @@ bytes_compare_seq(Bytes *lhs, DeeObject *rhs) { foreach_status == -2 || foreach_status == -3); if unlikely(foreach_status == -1) goto err; - if unlikely(foreach_status == -2) + if (foreach_status == -2) return -1; /* lhs < rhs */ - if unlikely(foreach_status == -3) + if (foreach_status == -3) return 1; /* lhs > rhs */ if (data.bcsd_index < data.bcsd_size) return 1; /* lhs > rhs */ diff --git a/src/deemon/objects/cached-dict.c b/src/deemon/objects/cached-dict.c index 0c9bddce3..a1cfe3a64 100644 --- a/src/deemon/objects/cached-dict.c +++ b/src/deemon/objects/cached-dict.c @@ -966,36 +966,6 @@ cdict_iscached_string_len_hash(DeeCachedDictObject *self, char const *key, } - -INTERN WUNUSED NONNULL((1, 2, 3)) DeeObject *DCALL -DeeCachedDict_GetItemNRDef(DeeCachedDictObject *self, - DeeObject *key, DeeObject *def) { - DeeObject *result = DeeCachedDict_TryGetItemNR(self, key); - if (result == ITER_DONE) - result = def; - return result; -} - -INTERN WUNUSED NONNULL((1, 2, 4)) DeeObject *DCALL -DeeCachedDict_GetItemNRStringHashDef(DeeCachedDictObject *__restrict self, - char const *__restrict key, - Dee_hash_t hash, DeeObject *def) { - DeeObject *result = DeeCachedDict_TryGetItemNRStringHash(self, key, hash); - if (result == ITER_DONE) - result = def; - return result; -} - -INTERN WUNUSED NONNULL((1, 2, 5)) DeeObject *DCALL -DeeCachedDict_GetItemNRStringLenHashDef(DeeCachedDictObject *__restrict self, - char const *__restrict key, - size_t keylen, Dee_hash_t hash, DeeObject *def) { - DeeObject *result = DeeCachedDict_TryGetItemNRStringLenHash(self, key, keylen, hash); - if (result == ITER_DONE) - result = def; - return result; -} - PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL cdict_sizeob(CachedDict *__restrict self) { return DeeObject_SizeOb(self->cd_map); @@ -1014,9 +984,14 @@ cdict_contains(CachedDict *self, DeeObject *key) { PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL cdict_nsi_getdefault(CachedDict *self, DeeObject *key, DeeObject *def) { - DeeObject *result = DeeCachedDict_GetItemNRDef(self, key, def); - if (ITER_ISOK(result)) + DeeObject *result = DeeCachedDict_TryGetItemNR(self, key); + if (result == ITER_DONE) { + result = def; + if (result != ITER_DONE) + Dee_Incref(result); + } else if (result) { Dee_Incref(result); + } return result; } @@ -1346,10 +1321,17 @@ cdict_init(CachedDict *__restrict self, PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL cdict_get(CachedDict *self, size_t argc, DeeObject *const *argv) { + DREF DeeObject *result; DeeObject *key, *def = Dee_None; if (DeeArg_Unpack(argc, argv, "o|o:get", &key, &def)) goto err; - return DeeCachedDict_GetItemNRDef(self, key, def); + result = DeeCachedDict_TryGetItemNR(self, key); + if unlikely(!result) + goto err; + if (result == ITER_DONE) + result = def; + Dee_Incref(result); + return result; err: return NULL; } diff --git a/src/deemon/objects/dict.c b/src/deemon/objects/dict.c index 49a719ad0..6e5b9c73a 100644 --- a/src/deemon/objects/dict.c +++ b/src/deemon/objects/dict.c @@ -1049,120 +1049,6 @@ dict_bounditem_string_len_hash(DeeObject *__restrict self, return -2; } -INTERN WUNUSED NONNULL((1, 2, 4)) DREF DeeObject *DCALL -DeeDict_GetItemStringHashDef(DeeObject *self, - char const *__restrict key, - dhash_t hash, - DeeObject *def) { - Dict *me = (Dict *)self; - DREF DeeObject *result; - dhash_t i, perturb; - DeeDict_LockRead(me); - perturb = i = DeeDict_HashSt(me, hash); - for (;; DeeDict_HashNx(i, perturb)) { - struct dict_item *item = DeeDict_HashIt(me, i); - if (!item->di_key) - break; /* Not found */ - if (item->di_hash != hash) - continue; /* Non-matching hash */ - if (!DeeString_Check(item->di_key)) - continue; /* NOTE: This also captures `dummy' */ - if (strcmp(DeeString_STR(item->di_key), key) == 0) { - result = item->di_value; - Dee_Incref(result); - DeeDict_LockEndRead(me); - return result; - } - } - DeeDict_LockEndRead(me); - if (def != ITER_DONE) - Dee_Incref(def); - return def; -} - -INTERN WUNUSED NONNULL((1, 2, 5)) DREF DeeObject *DCALL -DeeDict_GetItemStringLenHashDef(DeeObject *self, - char const *__restrict key, - size_t keylen, - dhash_t hash, - DeeObject *def) { - Dict *me = (Dict *)self; - DREF DeeObject *result; - dhash_t i, perturb; - DeeDict_LockRead(me); - perturb = i = DeeDict_HashSt(me, hash); - for (;; DeeDict_HashNx(i, perturb)) { - struct dict_item *item = DeeDict_HashIt(me, i); - if (!item->di_key) - break; /* Not found */ - if (item->di_hash != hash) - continue; /* Non-matching hash */ - if (!DeeString_Check(item->di_key)) - continue; /* NOTE: This also captures `dummy' */ - if (DeeString_EqualsBuf(item->di_key, key, keylen)) { - result = item->di_value; - Dee_Incref(result); - DeeDict_LockEndRead(me); - return result; - } - } - DeeDict_LockEndRead(me); - if (def != ITER_DONE) - Dee_Incref(def); - return def; -} - -INTERN WUNUSED NONNULL((1, 2)) bool DCALL -DeeDict_HasItemStringHash(DeeObject *__restrict self, - char const *__restrict key, - dhash_t hash) { - Dict *me = (Dict *)self; - dhash_t i, perturb; - DeeDict_LockRead(me); - perturb = i = DeeDict_HashSt(me, hash); - for (;; DeeDict_HashNx(i, perturb)) { - struct dict_item *item = DeeDict_HashIt(me, i); - if (!item->di_key) - break; /* Not found */ - if (item->di_hash != hash) - continue; /* Non-matching hash */ - if (!DeeString_Check(item->di_key)) - continue; /* NOTE: This also captures `dummy' */ - if (strcmp(DeeString_STR(item->di_key), key) == 0) { - DeeDict_LockEndRead(me); - return true; - } - } - DeeDict_LockEndRead(me); - return false; -} - -INTERN WUNUSED NONNULL((1, 2)) bool DCALL -DeeDict_HasItemStringLenHash(DeeObject *__restrict self, - char const *__restrict key, - size_t keylen, - dhash_t hash) { - Dict *me = (Dict *)self; - dhash_t i, perturb; - DeeDict_LockRead(me); - perturb = i = DeeDict_HashSt(me, hash); - for (;; DeeDict_HashNx(i, perturb)) { - struct dict_item *item = DeeDict_HashIt(me, i); - if (!item->di_key) - break; /* Not found */ - if (item->di_hash != hash) - continue; /* Non-matching hash */ - if (!DeeString_Check(item->di_key)) - continue; /* NOTE: This also captures `dummy' */ - if (DeeString_EqualsBuf(item->di_key, key, keylen)) { - DeeDict_LockEndRead(me); - return true; - } - } - DeeDict_LockEndRead(me); - return false; -} - INTERN WUNUSED NONNULL((1, 2)) int DCALL DeeDict_DelItemStringHash(DeeObject *__restrict self, char const *__restrict key, diff --git a/src/deemon/objects/map.c b/src/deemon/objects/map.c index b2c7b7380..c9163855b 100644 --- a/src/deemon/objects/map.c +++ b/src/deemon/objects/map.c @@ -63,10 +63,16 @@ map_byhash(DeeObject *self, size_t argc, PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL map_get(DeeObject *self, size_t argc, DeeObject *const *argv) { + DREF DeeObject *result; DeeObject *key, *def = Dee_None; if (DeeArg_Unpack(argc, argv, "o|o:get", &key, &def)) goto err; - return DeeObject_GetItemDef(self, key, def); + result = DeeObject_TryGetItem(self, key); + if (result == ITER_DONE) { + result = def; + Dee_Incref(def); + } + return result; err: return NULL; } @@ -83,7 +89,7 @@ map_setdefault(DeeObject *self, size_t argc, DeeObject *const *argv) { return (*nsi->nsi_maplike.nsi_setdefault)(self, key, value); /* Fallback: lookup key and override if not already present (thread-unsafe) */ - result = DeeObject_GetItemDef(self, key, ITER_DONE); + result = DeeObject_TryGetItem(self, key); if (result == ITER_DONE) { if unlikely(DeeObject_SetItem(self, key, value)) goto err; @@ -101,7 +107,7 @@ map_pop(DeeObject *self, size_t argc, DeeObject *const *argv) { DeeObject *key, *def = NULL; if (DeeArg_Unpack(argc, argv, "o|o:pop", &key, &def)) goto err; - result = DeeObject_GetItemDef(self, key, ITER_DONE); + result = DeeObject_TryGetItem(self, key); if (result == ITER_DONE) { /* Not present -> use default */ if (def) { @@ -227,7 +233,7 @@ map_setold(DeeObject *self, size_t argc, DeeObject *const *argv) { } /* Fallback: must use thread-unsafe (multi-step) operations. */ - old_value = DeeObject_GetItemDef(self, key, ITER_DONE); + old_value = DeeObject_TryGetItem(self, key); if (ITER_ISOK(old_value)) { Dee_Decref(old_value); if unlikely(DeeObject_SetItem(self, key, value)) @@ -258,7 +264,7 @@ map_setnew(DeeObject *self, size_t argc, DeeObject *const *argv) { } /* Fallback: must use thread-unsafe (multi-step) operations. */ - old_value = DeeObject_GetItemDef(self, key, ITER_DONE); + old_value = DeeObject_TryGetItem(self, key); if (ITER_ISOK(old_value)) { Dee_Decref(old_value); return_false; @@ -295,7 +301,7 @@ map_setold_ex(DeeObject *self, size_t argc, DeeObject *const *argv) { } /* Fallback: must use thread-unsafe (multi-step) operations. */ - old_value = DeeObject_GetItemDef(self, key, ITER_DONE); + old_value = DeeObject_TryGetItem(self, key); if (ITER_ISOK(old_value)) { if unlikely(DeeObject_SetItem(self, key, value)) { Dee_Decref(old_value); @@ -335,7 +341,7 @@ map_setnew_ex(DeeObject *self, size_t argc, DeeObject *const *argv) { } /* Fallback: must use thread-unsafe (multi-step) operations. */ - old_value = DeeObject_GetItemDef(self, key, ITER_DONE); + old_value = DeeObject_TryGetItem(self, key); if (ITER_ISOK(old_value)) { result = DeeTuple_Pack(2, Dee_False, old_value); Dee_Decref_unlikely(old_value); @@ -2102,7 +2108,7 @@ map_iterself(DeeObject *__restrict self) { PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL map_contains(DeeObject *self, DeeObject *key) { DREF DeeObject *value; - value = DeeObject_GetItemDef(self, key, ITER_DONE); + value = DeeObject_TryGetItem(self, key); if (!ITER_ISOK(value)) { if (value == ITER_DONE) return_false; @@ -2315,7 +2321,7 @@ map_eq_impl(DeeObject *__restrict self, if (DeeObject_Unpack(elem, 2, pair)) goto err_elem; Dee_Decref(elem); - other_value = DeeObject_GetItemDef(other, pair[0], ITER_DONE); + other_value = DeeObject_TryGetItem(other, pair[0]); Dee_Decref(pair[0]); if (!ITER_ISOK(other_value)) { Dee_Decref(pair[1]); diff --git a/src/deemon/objects/object.c b/src/deemon/objects/object.c index 7c4ad21bc..b78dc57fa 100644 --- a/src/deemon/objects/object.c +++ b/src/deemon/objects/object.c @@ -3342,13 +3342,20 @@ type_new_extended(DeeTypeObject *self, /* {(Type, ({(string, Object)...}, Tuple))...} */ /* {(Type, ({(string, Object)...}, Tuple, Mapping))...} */ - init_info = DeeObject_GetItemDef(initializer, (DeeObject *)first_base, Dee_None); + init_info = DeeObject_TryGetItem(initializer, (DeeObject *)first_base); if unlikely(!init_info) goto err_r; - temp = unpack_init_info(init_info, &init_fields, &init_args, &init_kw); - Dee_Decref(init_info); - if unlikely(temp) - goto err_r; + if (init_info == ITER_DONE) { + Dee_Incref(Dee_EmptyTuple); + init_args = Dee_EmptyTuple; + init_fields = NULL; + init_kw = NULL; + } else { + temp = unpack_init_info(init_info, &init_fields, &init_args, &init_kw); + Dee_Decref(init_info); + if unlikely(temp) + goto err_r; + } /* Invoke the mandatory base-type constructor. */ temp = type_invoke_base_constructor(first_base, result, @@ -3369,11 +3376,11 @@ type_new_extended(DeeTypeObject *self, do { if (iter == first_base) continue; - init_info = DeeObject_GetItemDef(initializer, - (DeeObject *)iter, - Dee_None); + init_info = DeeObject_TryGetItem(initializer, (DeeObject *)iter); if unlikely(!init_info) goto err_r_firstbase; + if (init_info == ITER_DONE) + continue; if (DeeNone_Check(init_info)) { Dee_DecrefNokill(init_info); continue; diff --git a/src/deemon/objects/seq.c b/src/deemon/objects/seq.c index 71955c077..14476e26d 100644 --- a/src/deemon/objects/seq.c +++ b/src/deemon/objects/seq.c @@ -2120,7 +2120,7 @@ DeeSeq_Compare(DeeObject *lhs, DeeObject *rhs) { return DeeSeq_CompareFS(lhs, lhs_size, rhs); lhs_iter = DeeObject_Iter(lhs); if unlikely(!lhs_iter) - return -2; + return Dee_COMPARE_ERR; result = DeeSeq_CompareIS(lhs_iter, rhs); Dee_Decref(lhs_iter); return result; @@ -2179,7 +2179,7 @@ seq_ne(DeeObject *self, DeeObject *other) { INTERN WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL seq_lo(DeeObject *self, DeeObject *other) { int result = DeeSeq_Compare(self, other); - if unlikely(result == -2) + if unlikely(result == Dee_COMPARE_ERR) goto err; return_bool_(result < 0); err: @@ -2189,7 +2189,7 @@ seq_lo(DeeObject *self, DeeObject *other) { PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL seq_le(DeeObject *self, DeeObject *other) { int result = DeeSeq_Compare(self, other); - if unlikely(result == -2) + if unlikely(result == Dee_COMPARE_ERR) goto err; return_bool_(result <= 0); err: @@ -2199,7 +2199,7 @@ seq_le(DeeObject *self, DeeObject *other) { PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL seq_gr(DeeObject *self, DeeObject *other) { int result = DeeSeq_Compare(self, other); - if unlikely(result == -2) + if unlikely(result == Dee_COMPARE_ERR) goto err; return_bool_(result > 0); err: @@ -2209,7 +2209,7 @@ seq_gr(DeeObject *self, DeeObject *other) { PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL seq_ge(DeeObject *self, DeeObject *other) { int result = DeeSeq_Compare(self, other); - if unlikely(result == -2) + if unlikely(result == Dee_COMPARE_ERR) goto err; return_bool_(result >= 0); err: diff --git a/src/deemon/objects/seq/bsearch-impl.c.inl b/src/deemon/objects/seq/bsearch-impl.c.inl index 448caba8e..772a24004 100644 --- a/src/deemon/objects/seq/bsearch-impl.c.inl +++ b/src/deemon/objects/seq/bsearch-impl.c.inl @@ -97,10 +97,10 @@ LOCAL_bfind_with_xxx( #ifndef DEFINE_DeeSeq_BLocate Dee_Decref(seq_elem); #endif /* !DEFINE_DeeSeq_BLocate */ + if unlikely(diff == Dee_COMPARE_ERR) + goto err; if (diff < 0) { - if unlikely(diff == -2) - goto err; /* keyed_search_item < self[mid] */ end = mid; } else if (diff > 0) { diff --git a/src/deemon/objects/seq/concat.c b/src/deemon/objects/seq/concat.c index d7e8e508c..c27ff8156 100644 --- a/src/deemon/objects/seq/concat.c +++ b/src/deemon/objects/seq/concat.c @@ -606,7 +606,7 @@ cat_bounditem_index(Cat *self, size_t index) { return -1; } -PRIVATE size_t DCALL +PRIVATE WUNUSED NONNULL((1, 4)) size_t DCALL cat_nsi_find(Cat *__restrict self, size_t start, size_t end, DeeObject *__restrict keyed_search_item, @@ -620,8 +620,8 @@ cat_nsi_find(Cat *__restrict self, if (OVERFLOW_UADD(offset, temp, &offset)) goto index_overflow; if unlikely(offset == (size_t)-1 || - offset == (size_t)-2) - goto index_overflow; + offset == (size_t)-2) + goto index_overflow; return offset; } temp = DeeObject_Size(DeeTuple_GET(self, i)); @@ -640,7 +640,7 @@ cat_nsi_find(Cat *__restrict self, return (size_t)-2; } -PRIVATE size_t DCALL +PRIVATE WUNUSED NONNULL((1, 4)) size_t DCALL cat_nsi_rfind(Cat *__restrict self, size_t start, size_t end, DeeObject *__restrict keyed_search_item, diff --git a/src/deemon/objects/seq/default-iterators.c b/src/deemon/objects/seq/default-iterators.c index 63212847f..0ed57ead4 100644 --- a/src/deemon/objects/seq/default-iterators.c +++ b/src/deemon/objects/seq/default-iterators.c @@ -102,7 +102,7 @@ di_gi_compare(DefaultIterator_WithGetItemIndex *self, } return Dee_Compare(self->digi_index, other->digi_index); err: - return -2; + return Dee_COMPARE_ERR; } PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL @@ -599,7 +599,7 @@ di_g_compare(DefaultIterator_WithGetItem *self, Dee_Decref(ot_index); return result; err: - return -2; + return Dee_COMPARE_ERR; } PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL @@ -1203,7 +1203,7 @@ di_nl_compare(DefaultIterator_WithNextAndLimit *self, } return result; err: - return -2; + return Dee_COMPARE_ERR; } PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL diff --git a/src/deemon/objects/seq/each.c b/src/deemon/objects/seq/each.c index 32c53cb9f..f1bf9c2d3 100644 --- a/src/deemon/objects/seq/each.c +++ b/src/deemon/objects/seq/each.c @@ -579,10 +579,11 @@ struct se_hasattr_string_len_hash_data { PRIVATE WUNUSED NONNULL((1, 2)) Dee_ssize_t DCALL se_foreach_hasattr_string_hash_cb(void *arg, DeeObject *elem) { + int status; struct se_hasattr_string_hash_data *attr; - attr = (struct se_hasattr_string_hash_data *)arg; - int status = DeeObject_HasAttrStringHash(elem, attr->shashd_attr, - attr->shashd_hash); + attr = (struct se_hasattr_string_hash_data *)arg; + status = DeeObject_HasAttrStringHash(elem, attr->shashd_attr, + attr->shashd_hash); if unlikely(status <= 0) return status < 0 ? -1 : -2; return 0; @@ -590,11 +591,12 @@ se_foreach_hasattr_string_hash_cb(void *arg, DeeObject *elem) { PRIVATE WUNUSED NONNULL((1, 2)) Dee_ssize_t DCALL se_foreach_hasattr_string_len_hash_cb(void *arg, DeeObject *elem) { + int status; struct se_hasattr_string_len_hash_data *attr; attr = (struct se_hasattr_string_len_hash_data *)arg; - int status = DeeObject_HasAttrStringLenHash(elem, attr->shaslhd_attr, - attr->shaslhd_attrlen, - attr->shaslhd_hash); + status = DeeObject_HasAttrStringLenHash(elem, attr->shaslhd_attr, + attr->shaslhd_attrlen, + attr->shaslhd_hash); if unlikely(status <= 0) return status < 0 ? -1 : -2; return 0; diff --git a/src/deemon/objects/seq_functions.c b/src/deemon/objects/seq_functions.c index f1a590d22..47747b528 100644 --- a/src/deemon/objects/seq_functions.c +++ b/src/deemon/objects/seq_functions.c @@ -1198,7 +1198,7 @@ DeeSeq_EndsWith(DeeObject *self, goto err; } -PRIVATE size_t DCALL +PRIVATE WUNUSED NONNULL((1, 2)) size_t DCALL iterator_find(DeeObject *__restrict iterator, DeeObject *__restrict keyed_search_item, size_t start, size_t end, @@ -1709,7 +1709,7 @@ INTDEF WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL DeeSeq_SplitSeq(DeeObject * /* Sequence compare */ /************************************************************************/ -/* @return: == -2: An error occurred. +/* @return: == Dee_COMPARE_ERR: An error occurred. * @return: == -1: `self < some_object' * @return: == 0: Objects compare as equal * @return: == 1: `self > some_object' */ @@ -1735,7 +1735,7 @@ DeeSeq_CompareVF(DeeObject *const *lhsv, size_t lhsc, DREF DeeObject *rhs_item; rhs_item = DeeFastSeq_GetItem_deprecated(rhs, i); if unlikely(!rhs_item) - return -2; + return Dee_COMPARE_ERR; diff = DeeObject_Compare(lhsv[i], rhs_item); Dee_Decref(rhs_item); if (diff != 0) @@ -1755,7 +1755,7 @@ DeeSeq_CompareVI(DeeObject *const *lhsv, size_t lhsc, if unlikely(!ITER_ISOK(rhs_item)) { if (rhs_item == ITER_DONE) return 1; /* COUNT(LHS) > COUNT(RHS) */ - return -2; + return Dee_COMPARE_ERR; } diff = DeeObject_Compare(lhsv[i], rhs_item); Dee_Decref(rhs_item); @@ -1766,7 +1766,7 @@ DeeSeq_CompareVI(DeeObject *const *lhsv, size_t lhsc, if (!ITER_ISOK(rhs_item)) { if (rhs_item == ITER_DONE) return 0; /* COUNT(LHS) == COUNT(RHS) */ - return -2; + return Dee_COMPARE_ERR; } Dee_Decref(rhs_item); return -1; /* COUNT(LHS) < COUNT(RHS) */ @@ -1785,7 +1785,7 @@ DeeSeq_CompareVS(DeeObject *const *lhsv, size_t lhsc, DREF DeeObject *rhs_iter; rhs_iter = DeeObject_Iter(rhs); if unlikely(!rhs_iter) - return -2; + return Dee_COMPARE_ERR; result = DeeSeq_CompareVI(lhsv, lhsc, rhs_iter); Dee_Decref(rhs_iter); } @@ -1801,7 +1801,7 @@ DeeSeq_CompareFV(DeeObject *lhs, size_t lhsc, DREF DeeObject *lhs_item; lhs_item = DeeFastSeq_GetItem_deprecated(lhs, i); if unlikely(!lhs_item) - return -2; + return Dee_COMPARE_ERR; diff = DeeObject_Compare(lhs_item, rhsv[i]); Dee_Decref(lhs_item); if (diff != 0) @@ -1819,11 +1819,11 @@ DeeSeq_CompareFF(DeeObject *lhs, size_t lhsc, DeeObject *rhs, size_t rhsc) { DREF DeeObject *rhs_item; lhs_item = DeeFastSeq_GetItem_deprecated(lhs, i); if unlikely(!lhs_item) - return -2; + return Dee_COMPARE_ERR; rhs_item = DeeFastSeq_GetItem_deprecated(rhs, i); if unlikely(!rhs_item) { Dee_Decref(lhs_item); - return -2; + return Dee_COMPARE_ERR; } diff = DeeObject_Compare(lhs_item, rhs_item); Dee_Decref(rhs_item); @@ -1843,13 +1843,13 @@ DeeSeq_CompareFI(DeeObject *lhs, size_t lhsc, DeeObject *rhs) { int diff; lhs_item = DeeFastSeq_GetItem_deprecated(lhs, i); if unlikely(!lhs_item) - return -2; + return Dee_COMPARE_ERR; rhs_item = DeeObject_IterNext(rhs); if unlikely(!ITER_ISOK(rhs_item)) { Dee_Decref(lhs_item); if (rhs_item == ITER_DONE) return 1; /* COUNT(LHS) > COUNT(RHS) */ - return -2; + return Dee_COMPARE_ERR; } diff = DeeObject_Compare(lhs_item, rhs_item); Dee_Decref(rhs_item); @@ -1861,7 +1861,7 @@ DeeSeq_CompareFI(DeeObject *lhs, size_t lhsc, DeeObject *rhs) { if (!ITER_ISOK(rhs_item)) { if (rhs_item == ITER_DONE) return 0; /* COUNT(LHS) == COUNT(RHS) */ - return -2; + return Dee_COMPARE_ERR; } Dee_Decref(rhs_item); return -1; /* COUNT(LHS) < COUNT(RHS) */ @@ -1879,7 +1879,7 @@ DeeSeq_CompareFS(DeeObject *lhs, size_t lhsc, DeeObject *rhs) { DREF DeeObject *rhs_iter; rhs_iter = DeeObject_Iter(rhs); if unlikely(!rhs_iter) - return -2; + return Dee_COMPARE_ERR; result = DeeSeq_CompareFI(lhs, lhsc, rhs_iter); Dee_Decref(rhs_iter); } @@ -1898,7 +1898,7 @@ DeeSeq_CompareIV(DeeObject *lhs, if unlikely(!ITER_ISOK(lhs_item)) { if (lhs_item == ITER_DONE) return -1; /* COUNT(LHS) < COUNT(RHS) */ - return -2; + return Dee_COMPARE_ERR; } diff = DeeObject_Compare(lhs_item, rhsv[i]); Dee_Decref(lhs_item); @@ -1909,7 +1909,7 @@ DeeSeq_CompareIV(DeeObject *lhs, if (!ITER_ISOK(lhs_item)) { if (lhs_item == ITER_DONE) return 0; /* COUNT(LHS) == COUNT(RHS) */ - return -2; + return Dee_COMPARE_ERR; } Dee_Decref(lhs_item); return 1; /* COUNT(LHS) > COUNT(RHS) */ @@ -1927,12 +1927,12 @@ DeeSeq_CompareIF(DeeObject *lhs, if unlikely(!ITER_ISOK(lhs_item)) { if (lhs_item == ITER_DONE) return -1; /* COUNT(LHS) < COUNT(RHS) */ - return -2; + return Dee_COMPARE_ERR; } rhs_item = DeeFastSeq_GetItem_deprecated(rhs, i); if unlikely(!rhs_item) { Dee_Decref(lhs_item); - return -2; + return Dee_COMPARE_ERR; } diff = DeeObject_Compare(lhs_item, rhs_item); Dee_Decref(rhs_item); @@ -1944,7 +1944,7 @@ DeeSeq_CompareIF(DeeObject *lhs, if (!ITER_ISOK(lhs_item)) { if (lhs_item == ITER_DONE) return 0; /* COUNT(LHS) == COUNT(RHS) */ - return -2; + return Dee_COMPARE_ERR; } Dee_Decref(lhs_item); return 1; /* COUNT(LHS) > COUNT(RHS) */ @@ -1960,11 +1960,11 @@ DeeSeq_CompareII(DeeObject *lhs, lhs_item = DeeObject_IterNext(lhs); if unlikely(!ITER_ISOK(lhs_item)) { if unlikely(lhs_item != ITER_DONE) - return -2; + return Dee_COMPARE_ERR; rhs_item = DeeObject_IterNext(rhs); if (!ITER_ISOK(rhs_item)) { if unlikely(rhs_item != ITER_DONE) - return -2; + return Dee_COMPARE_ERR; return 0; /* COUNT(LHS) == COUNT(RHS) */ } Dee_Decref(rhs_item); @@ -1974,7 +1974,7 @@ DeeSeq_CompareII(DeeObject *lhs, if unlikely(!ITER_ISOK(rhs_item)) { Dee_Decref(lhs_item); if unlikely(rhs_item != ITER_DONE) - return -2; + return Dee_COMPARE_ERR; return 1; /* COUNT(LHS) > COUNT(RHS) */ } diff = DeeObject_Compare(lhs_item, rhs_item); @@ -1998,7 +1998,7 @@ DeeSeq_CompareIS(DeeObject *lhs, DREF DeeObject *rhs_iter; rhs_iter = DeeObject_Iter(rhs); if unlikely(!rhs_iter) - return -2; + return Dee_COMPARE_ERR; result = DeeSeq_CompareII(lhs, rhs_iter); Dee_Decref(rhs_iter); } @@ -2032,7 +2032,7 @@ DeeSeq_EqVF(DeeObject *const *lhsv, DREF DeeObject *rhs_item; rhs_item = DeeFastSeq_GetItem_deprecated(rhs, i); if unlikely(!rhs_item) - return -2; + return -1; diff = DeeObject_TryCmpEqAsBool(lhsv[i], rhs_item); Dee_Decref(rhs_item); if (diff <= 0) diff --git a/src/deemon/runtime/attribute.c b/src/deemon/runtime/attribute.c index 7c43ceb7b..c922a1f21 100644 --- a/src/deemon/runtime/attribute.c +++ b/src/deemon/runtime/attribute.c @@ -343,6 +343,15 @@ PUBLIC WUNUSED NONNULL((1, 2)) int return DeeObject_HasAttrStringHash(self, attr, Dee_HashStr(attr)); } +/* Check if a given attribute exists and/or is bound. + * @return: 1: Attribute is bound. + * @return: 0: Attribute isn't bound. + * @return: -1: An error occurred. + * @return: -2: The attribute doesn't exist. + * @return: -3: A user-defined getattr operator threw an error indicating + * that the attribute doesn't exists. - Should be handled the + * same way as `-2', however search for the + * attribute should not continue. */ PUBLIC WUNUSED NONNULL((1, 2)) int (DCALL DeeObject_BoundAttrString)(DeeObject *__restrict self, char const *__restrict attr) { diff --git a/src/deemon/runtime/notify.c b/src/deemon/runtime/notify.c index 26d55f483..0936ceef9 100644 --- a/src/deemon/runtime/notify.c +++ b/src/deemon/runtime/notify.c @@ -48,7 +48,7 @@ Dee_GetEnv(DeeObject *__restrict name) { (DeeObject *)&str_environ); if unlikely(!posix_environ) goto err_tryhandle; - result = DeeObject_GetItemDef(posix_environ, name, ITER_DONE); + result = DeeObject_TryGetItem(posix_environ, name); Dee_Decref(posix_environ); if unlikely(!result) goto err_tryhandle; diff --git a/src/deemon/runtime/operator.c b/src/deemon/runtime/operator.c index e40f40d68..192f9cac7 100644 --- a/src/deemon/runtime/operator.c +++ b/src/deemon/runtime/operator.c @@ -12044,8 +12044,8 @@ DEFINE_TYPE_INHERIT_FUNCTION(DeeType_InheritPow, "operator pow", pow, Pow) DEFINE_OPERATOR(DREF DeeObject *, Inv, (DeeObject *RESTRICT_IF_NOTYPE self)) { LOAD_TP_SELF; - if likely((tp_self->tp_math && tp_self->tp_math->tp_inv) || - DeeType_InheritInv(tp_self)) + if likely(likely(tp_self->tp_math && tp_self->tp_math->tp_inv) || + unlikely(DeeType_InheritInv(tp_self))) return DeeType_INVOKE_INV(tp_self, self); err_unimplemented_operator(tp_self, OPERATOR_INV); return NULL; @@ -12053,8 +12053,8 @@ DEFINE_OPERATOR(DREF DeeObject *, Inv, (DeeObject *RESTRICT_IF_NOTYPE self)) { DEFINE_OPERATOR(DREF DeeObject *, Pos, (DeeObject *RESTRICT_IF_NOTYPE self)) { LOAD_TP_SELF; - if likely((tp_self->tp_math && tp_self->tp_math->tp_pos) || - DeeType_InheritPos(tp_self)) + if likely(likely(tp_self->tp_math && tp_self->tp_math->tp_pos) || + unlikely(DeeType_InheritPos(tp_self))) return DeeType_INVOKE_POS(tp_self, self); err_unimplemented_operator(tp_self, OPERATOR_POS); return NULL; @@ -12062,8 +12062,8 @@ DEFINE_OPERATOR(DREF DeeObject *, Pos, (DeeObject *RESTRICT_IF_NOTYPE self)) { DEFINE_OPERATOR(DREF DeeObject *, Neg, (DeeObject *RESTRICT_IF_NOTYPE self)) { LOAD_TP_SELF; - if likely((tp_self->tp_math && tp_self->tp_math->tp_neg) || - DeeType_InheritNeg(tp_self)) + if likely(likely(tp_self->tp_math && tp_self->tp_math->tp_neg) || + unlikely(DeeType_InheritNeg(tp_self))) return DeeType_INVOKE_NEG(tp_self, self); err_unimplemented_operator(tp_self, OPERATOR_NEG); return NULL; @@ -12071,8 +12071,8 @@ DEFINE_OPERATOR(DREF DeeObject *, Neg, (DeeObject *RESTRICT_IF_NOTYPE self)) { DEFINE_OPERATOR(DREF DeeObject *, Add, (DeeObject *self, DeeObject *some_object)) { LOAD_TP_SELF; - if likely((tp_self->tp_math && tp_self->tp_math->tp_add) || - (DeeType_InheritAdd(tp_self) && tp_self->tp_math->tp_add)) + if likely(likely(tp_self->tp_math && tp_self->tp_math->tp_add) || + unlikely(DeeType_InheritAdd(tp_self) && tp_self->tp_math->tp_add)) return DeeType_INVOKE_ADD(tp_self, self, some_object); err_unimplemented_operator(tp_self, OPERATOR_ADD); return NULL; @@ -12080,23 +12080,23 @@ DEFINE_OPERATOR(DREF DeeObject *, Add, (DeeObject *self, DeeObject *some_object) DEFINE_OPERATOR(DREF DeeObject *, Sub, (DeeObject *self, DeeObject *some_object)) { LOAD_TP_SELF; - if likely((tp_self->tp_math && tp_self->tp_math->tp_sub) || - (DeeType_InheritAdd(tp_self) && tp_self->tp_math->tp_sub)) + if likely(likely(tp_self->tp_math && tp_self->tp_math->tp_sub) || + unlikely(DeeType_InheritAdd(tp_self) && tp_self->tp_math->tp_sub)) return DeeType_INVOKE_SUB(tp_self, self, some_object); err_unimplemented_operator(tp_self, OPERATOR_SUB); return NULL; } -#define DEFINE_MATH_OPERATOR2(name, xxx, operator_name, invoke, inherit) \ - DEFINE_OPERATOR(DREF DeeObject *, name, \ - (DeeObject *self, DeeObject *some_object)) { \ - LOAD_TP_SELF; \ - ASSERT_OBJECT(some_object); \ - if likely((tp_self->tp_math && tp_self->tp_math->tp_##xxx) || \ - inherit(tp_self)) \ - return invoke(tp_self, self, some_object); \ - err_unimplemented_operator(tp_self, operator_name); \ - return NULL; \ +#define DEFINE_MATH_OPERATOR2(name, xxx, operator_name, invoke, inherit) \ + DEFINE_OPERATOR(DREF DeeObject *, name, \ + (DeeObject *self, DeeObject *some_object)) { \ + LOAD_TP_SELF; \ + ASSERT_OBJECT(some_object); \ + if likely(likely(tp_self->tp_math && tp_self->tp_math->tp_##xxx) || \ + unlikely(inherit(tp_self))) \ + return invoke(tp_self, self, some_object); \ + err_unimplemented_operator(tp_self, operator_name); \ + return NULL; \ } DEFINE_MATH_OPERATOR2(Mul, mul, OPERATOR_MUL, DeeType_INVOKE_MUL, DeeType_InheritMul) DEFINE_MATH_OPERATOR2(Div, div, OPERATOR_DIV, DeeType_INVOKE_DIV, DeeType_InheritDiv) @@ -12289,16 +12289,16 @@ DeeObject_XorUInt32(DeeObject *__restrict self, uint32_t val) { DEFINE_OPERATOR(int, Inc, (DREF DeeObject **__restrict p_self)) { LOAD_TP_SELFP; - if likely((tp_self->tp_math && tp_self->tp_math->tp_inc) || - (DeeType_InheritAdd(tp_self) && tp_self->tp_math->tp_inc)) + if likely(likely(tp_self->tp_math && tp_self->tp_math->tp_inc) || + unlikely(DeeType_InheritAdd(tp_self) && tp_self->tp_math->tp_inc)) return DeeType_INVOKE_INC(tp_self, p_self); return err_unimplemented_operator(tp_self, OPERATOR_INC); } DEFINE_OPERATOR(int, Dec, (DREF DeeObject **__restrict p_self)) { LOAD_TP_SELFP; - if likely((tp_self->tp_math && tp_self->tp_math->tp_dec) || - (DeeType_InheritAdd(tp_self) && tp_self->tp_math->tp_dec)) + if likely(likely(tp_self->tp_math && tp_self->tp_math->tp_dec) || + unlikely(DeeType_InheritAdd(tp_self) && tp_self->tp_math->tp_dec)) return DeeType_INVOKE_DEC(tp_self, p_self); return err_unimplemented_operator(tp_self, OPERATOR_DEC); } @@ -12307,8 +12307,8 @@ DEFINE_OPERATOR(int, InplaceAdd, (DREF DeeObject **__restrict p_self, DeeObject *some_object)) { LOAD_TP_SELFP; ASSERT_OBJECT(some_object); - if likely((tp_self->tp_math && tp_self->tp_math->tp_inplace_add) || - (DeeType_InheritAdd(tp_self) && tp_self->tp_math->tp_inplace_add)) + if likely(likely(tp_self->tp_math && tp_self->tp_math->tp_inplace_add) || + unlikely(DeeType_InheritAdd(tp_self) && tp_self->tp_math->tp_inplace_add)) return DeeType_INVOKE_IADD(tp_self, p_self, some_object); return err_unimplemented_operator(tp_self, OPERATOR_INPLACE_ADD); } @@ -12317,8 +12317,8 @@ DEFINE_OPERATOR(int, InplaceSub, (DREF DeeObject **__restrict p_self, DeeObject *some_object)) { LOAD_TP_SELFP; ASSERT_OBJECT(some_object); - if likely((tp_self->tp_math && tp_self->tp_math->tp_inplace_sub) || - (DeeType_InheritAdd(tp_self) && tp_self->tp_math->tp_inplace_sub)) + if likely(likely(tp_self->tp_math && tp_self->tp_math->tp_inplace_sub) || + unlikely(DeeType_InheritAdd(tp_self) && tp_self->tp_math->tp_inplace_sub)) return DeeType_INVOKE_ISUB(tp_self, p_self, some_object); return err_unimplemented_operator(tp_self, OPERATOR_INPLACE_SUB); } @@ -12328,8 +12328,8 @@ DEFINE_OPERATOR(int, InplaceSub, (DREF DeeObject **__restrict p_self, DeeObject *some_object)) { \ LOAD_TP_SELFP; \ ASSERT_OBJECT(some_object); \ - if likely((tp_self->tp_math && tp_self->tp_math->tp_inplace_##xxx) || \ - inherit(tp_self)) \ + if likely(likely(tp_self->tp_math && tp_self->tp_math->tp_inplace_##xxx) || \ + unlikely(inherit(tp_self))) \ return invoke_inplace(tp_self, p_self, some_object); \ return err_unimplemented_operator(tp_self, operator_name); \ } @@ -12376,16 +12376,16 @@ DEFINE_MATH_INPLACE_INT_OPERATOR(DeeObject_InplaceXorUInt32, DeeObject_InplaceXo #endif /* !DEFINE_TYPED_OPERATORS */ -#define DEFINE_OBJECT_COMPARE_OPERATOR(name, tp_xx, operator_name, invoke) \ - DEFINE_OPERATOR(DREF DeeObject *, name, \ - (DeeObject *self, DeeObject *some_object)) { \ - LOAD_TP_SELF; \ - ASSERT_OBJECT(some_object); \ - if likely((tp_self->tp_cmp && tp_self->tp_cmp->tp_xx) || \ - (DeeType_InheritCompare(tp_self) && tp_self->tp_cmp->tp_xx)) \ - return invoke(tp_self, self, some_object); \ - err_unimplemented_operator(tp_self, operator_name); \ - return NULL; \ +#define DEFINE_OBJECT_COMPARE_OPERATOR(name, tp_xx, operator_name, invoke) \ + DEFINE_OPERATOR(DREF DeeObject *, name, \ + (DeeObject *self, DeeObject *some_object)) { \ + LOAD_TP_SELF; \ + ASSERT_OBJECT(some_object); \ + if likely(likely(tp_self->tp_cmp && tp_self->tp_cmp->tp_xx) || \ + unlikely(DeeType_InheritCompare(tp_self) && tp_self->tp_cmp->tp_xx)) \ + return invoke(tp_self, self, some_object); \ + err_unimplemented_operator(tp_self, operator_name); \ + return NULL; \ } DEFINE_OBJECT_COMPARE_OPERATOR(CmpEq, tp_eq, OPERATOR_EQ, DeeType_INVOKE_EQ) DEFINE_OBJECT_COMPARE_OPERATOR(CmpNe, tp_ne, OPERATOR_NE, DeeType_INVOKE_NE) @@ -12449,8 +12449,8 @@ PUBLIC WUNUSED NONNULL((1, 2)) int * @return: == Dee_COMPARE_ERR: An error occurred. */ DEFINE_OPERATOR(int, Compare, (DeeObject *self, DeeObject *rhs)) { LOAD_TP_SELF; - if likely((tp_self->tp_cmp && tp_self->tp_cmp->tp_compare) || - (DeeType_InheritCompare(tp_self) && tp_self->tp_cmp->tp_compare)) + if likely(likely(tp_self->tp_cmp && tp_self->tp_cmp->tp_compare) || + unlikely(DeeType_InheritCompare(tp_self) && tp_self->tp_cmp->tp_compare)) return DeeType_INVOKE_COMPARE(tp_self, self, rhs); err_unimplemented_operator(tp_self, OPERATOR_LO); return Dee_COMPARE_ERR; @@ -12462,8 +12462,8 @@ DEFINE_OPERATOR(int, Compare, (DeeObject *self, DeeObject *rhs)) { * @return: == Dee_COMPARE_ERR: An error occurred. */ DEFINE_OPERATOR(int, CompareEq, (DeeObject *self, DeeObject *rhs)) { LOAD_TP_SELF; - if ((tp_self->tp_cmp && tp_self->tp_cmp->tp_compare_eq) || - (DeeType_InheritCompare(tp_self) && tp_self->tp_cmp->tp_compare_eq)) + if likely(likely(tp_self->tp_cmp && tp_self->tp_cmp->tp_compare_eq) || + unlikely(DeeType_InheritCompare(tp_self) && tp_self->tp_cmp->tp_compare_eq)) return DeeType_INVOKE_COMPAREEQ(tp_self, self, rhs); err_unimplemented_operator(tp_self, OPERATOR_EQ); return Dee_COMPARE_ERR; @@ -15625,8 +15625,8 @@ DeeType_InheritBool(DeeTypeObject *__restrict self) { DEFINE_OPERATOR(DREF DeeObject *, Iter, (DeeObject *RESTRICT_IF_NOTYPE self)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_iter) || - DeeType_InheritIter(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_iter) || + unlikely(DeeType_InheritIter(tp_self))) return DeeType_INVOKE_ITER(tp_self, self); err_unimplemented_operator(tp_self, OPERATOR_ITER); return NULL; @@ -15634,7 +15634,8 @@ DEFINE_OPERATOR(DREF DeeObject *, Iter, (DeeObject *RESTRICT_IF_NOTYPE self)) { DEFINE_OPERATOR(DREF DeeObject *, IterNext, (DeeObject *RESTRICT_IF_NOTYPE self)) { LOAD_TP_SELF; - if likely(tp_self->tp_iter_next || DeeType_InheritIterNext(tp_self)) + if likely(likely(tp_self->tp_iter_next) || + unlikely(DeeType_InheritIterNext(tp_self))) return DeeType_INVOKE_NEXT(tp_self, self); err_unimplemented_operator(tp_self, OPERATOR_ITERNEXT); return NULL; @@ -15650,13 +15651,14 @@ DEFINE_OPERATOR(DREF DeeObject *, IterNext, (DeeObject *RESTRICT_IF_NOTYPE self) DEFINE_OPERATOR(size_t, IterAdvance, (DeeObject *__restrict self, size_t step)) { size_t result = 0; DREF DeeObject *(DCALL *tp_iter_next)(DeeObject *__restrict self); + LOAD_TP_SELF; if unlikely(!step) goto done; - if unlikely(!Dee_TYPE(self)->tp_iter_next && - !DeeType_InheritIterNext(Dee_TYPE(self))) + if unlikely(!tp_self->tp_iter_next && + !DeeType_InheritIterNext(tp_self)) goto err_no_iter_next; /* TODO: Type-specific optimizations */ - tp_iter_next = Dee_TYPE(self)->tp_iter_next; + tp_iter_next = tp_self->tp_iter_next; do { DREF DeeObject *elem = (*tp_iter_next)(self); if unlikely(!ITER_ISOK(elem)) { @@ -15670,7 +15672,7 @@ DEFINE_OPERATOR(size_t, IterAdvance, (DeeObject *__restrict self, size_t step)) done: return result; err_no_iter_next: - err_unimplemented_operator(Dee_TYPE(self), OPERATOR_ITERNEXT); + err_unimplemented_operator(tp_self, OPERATOR_ITERNEXT); err: return (size_t)-1; } @@ -15679,7 +15681,8 @@ DEFINE_OPERATOR(size_t, IterAdvance, (DeeObject *__restrict self, size_t step)) /* @return: (size_t)-1: Fast size cannot be determined */ DEFINE_OPERATOR(size_t, SizeFast, (DeeObject *RESTRICT_IF_NOTYPE self)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_size_fast) || DeeType_InheritSize(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_size_fast) || + unlikely(DeeType_InheritSize(tp_self))) return DeeType_INVOKE_SIZEFAST(tp_self, self); return (size_t)-1; } @@ -15687,8 +15690,8 @@ DEFINE_OPERATOR(size_t, SizeFast, (DeeObject *RESTRICT_IF_NOTYPE self)) { DEFINE_OPERATOR(size_t, Size, (DeeObject *RESTRICT_IF_NOTYPE self)) { #ifdef CONFIG_NO_EXPERIMENTAL_NEW_SEQUENCE_OPERATORS LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_size) || - (DeeType_InheritSize(tp_self) && tp_self->tp_seq->tp_size)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_size) || + unlikely(DeeType_InheritSize(tp_self) && tp_self->tp_seq->tp_size)) return DeeType_INVOKE_SIZE(tp_self, self); return (size_t)err_unimplemented_operator(tp_self, OPERATOR_SIZE); #else /* CONFIG_NO_EXPERIMENTAL_NEW_SEQUENCE_OPERATORS */ @@ -15696,7 +15699,7 @@ DEFINE_OPERATOR(size_t, Size, (DeeObject *RESTRICT_IF_NOTYPE self)) { size_t result; LOAD_TP_SELF; if likely((tp_self->tp_seq && tp_self->tp_seq->tp_sizeob) || - DeeType_InheritSize(tp_self)) { + unlikely(DeeType_InheritSize(tp_self))) { struct type_nsi const *nsi; /* NSI optimizations. */ nsi = tp_self->tp_seq->tp_nsi; @@ -15741,8 +15744,8 @@ DEFINE_OPERATOR(int, ContainsAsBool, DEFINE_OPERATOR(DREF DeeObject *, SizeOb, (DeeObject *RESTRICT_IF_NOTYPE self)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_sizeob) || - DeeType_InheritSize(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_sizeob) || + unlikely(DeeType_InheritSize(tp_self))) return DeeType_INVOKE_SIZEOB(tp_self, self); err_unimplemented_operator(tp_self, OPERATOR_SIZE); return NULL; @@ -15751,8 +15754,8 @@ DEFINE_OPERATOR(DREF DeeObject *, SizeOb, DEFINE_OPERATOR(DREF DeeObject *, Contains, (DeeObject *self, DeeObject *some_object)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_contains) || - DeeType_InheritContains(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_contains) || + unlikely(DeeType_InheritContains(tp_self))) return DeeType_INVOKE_CONTAINS(tp_self, self, some_object); err_unimplemented_operator(tp_self, OPERATOR_CONTAINS); return NULL; @@ -15761,8 +15764,8 @@ DEFINE_OPERATOR(DREF DeeObject *, Contains, DEFINE_OPERATOR(DREF DeeObject *, GetItem, (DeeObject *self, DeeObject *index)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getitem) || - DeeType_InheritGetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getitem) || + unlikely(DeeType_InheritGetItem(tp_self))) return DeeType_INVOKE_GETITEM(tp_self, self, index); err_unimplemented_operator(tp_self, OPERATOR_GETITEM); return NULL; @@ -15771,8 +15774,8 @@ DEFINE_OPERATOR(DREF DeeObject *, GetItem, DEFINE_OPERATOR(int, DelItem, (DeeObject *self, DeeObject *index)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_delitem) || - DeeType_InheritDelItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_delitem) || + unlikely(DeeType_InheritDelItem(tp_self))) return DeeType_INVOKE_DELITEM(tp_self, self, index); return err_unimplemented_operator(tp_self, OPERATOR_DELITEM); } @@ -15780,8 +15783,8 @@ DEFINE_OPERATOR(int, DelItem, DEFINE_OPERATOR(int, SetItem, (DeeObject *self, DeeObject *index, DeeObject *value)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_setitem) || - DeeType_InheritSetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_setitem) || + unlikely(DeeType_InheritSetItem(tp_self))) return DeeType_INVOKE_SETITEM(tp_self, self, index, value); return err_unimplemented_operator(tp_self, OPERATOR_SETITEM); } @@ -15789,8 +15792,8 @@ DEFINE_OPERATOR(int, SetItem, DEFINE_OPERATOR(DREF DeeObject *, GetRange, (DeeObject *self, DeeObject *start, DeeObject *end)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getrange) || - DeeType_InheritGetRange(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getrange) || + unlikely(DeeType_InheritGetRange(tp_self))) return DeeType_INVOKE_GETRANGE(tp_self, self, start, end); err_unimplemented_operator(tp_self, OPERATOR_GETRANGE); return NULL; @@ -15847,17 +15850,20 @@ DEFINE_OPERATOR(DREF DeeObject *, GetRangeBeginIndex, LOAD_TP_SELF; ASSERT_OBJECT(end); if (DeeNone_Check(end)) { - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getrange_index_n) || DeeType_InheritGetRange(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getrange_index_n) || + unlikely(DeeType_InheritGetRange(tp_self))) return DeeType_INVOKE_GETRANGEINDEXN(tp_self, self, start); } else if (DeeInt_Check(end)) { - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getrange_index) || DeeType_InheritGetRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getrange_index) || + unlikely(DeeType_InheritGetRange(tp_self))) { Dee_ssize_t end_index; if (DeeInt_AsSSize(end, &end_index)) goto err; return DeeType_INVOKE_GETRANGEINDEX(tp_self, self, start, end_index); } } else { - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getrange) || DeeType_InheritGetRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getrange) || + unlikely(DeeType_InheritGetRange(tp_self))) { DREF DeeObject *result; DREF DeeObject *start_ob = DeeInt_NewSSize(start); if unlikely(!start_ob) @@ -15902,7 +15908,8 @@ DEFINE_OPERATOR(DREF DeeObject *, GetRangeEndIndex, DEFINE_OPERATOR(DREF DeeObject *, GetRangeIndex, (DeeObject *RESTRICT_IF_NOTYPE self, Dee_ssize_t start, Dee_ssize_t end)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getrange_index) || DeeType_InheritGetRange(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getrange_index) || + unlikely(DeeType_InheritGetRange(tp_self))) return DeeType_INVOKE_GETRANGEINDEX(tp_self, self, start, end); err_unimplemented_operator(tp_self, OPERATOR_GETRANGE); return NULL; @@ -15911,7 +15918,8 @@ DEFINE_OPERATOR(DREF DeeObject *, GetRangeIndex, DEFINE_OPERATOR(DREF DeeObject *, GetRangeIndexN, (DeeObject *RESTRICT_IF_NOTYPE self, Dee_ssize_t start)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getrange_index_n) || DeeType_InheritGetRange(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getrange_index_n) || + unlikely(DeeType_InheritGetRange(tp_self))) return DeeType_INVOKE_GETRANGEINDEXN(tp_self, self, start); err_unimplemented_operator(tp_self, OPERATOR_GETRANGE); return NULL; @@ -15921,17 +15929,20 @@ DEFINE_OPERATOR(int, DelRangeBeginIndex, (DeeObject *self, Dee_ssize_t start, DeeObject *end)) { LOAD_TP_SELF; if (DeeNone_Check(end)) { - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_delrange_index_n) || DeeType_InheritDelRange(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_delrange_index_n) || + unlikely(DeeType_InheritDelRange(tp_self))) return DeeType_INVOKE_DELRANGEINDEXN(tp_self, self, start); } else if (DeeInt_Check(end)) { - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_delrange_index) || DeeType_InheritDelRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_delrange_index) || + unlikely(DeeType_InheritDelRange(tp_self))) { Dee_ssize_t end_index; if (DeeInt_AsSSize(end, &end_index)) goto err; return DeeType_INVOKE_DELRANGEINDEX(tp_self, self, start, end_index); } } else { - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_delrange) || DeeType_InheritDelRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_delrange) || + unlikely(DeeType_InheritDelRange(tp_self))) { int result; DREF DeeObject *start_ob = DeeInt_NewSSize(start); if unlikely(!start_ob) @@ -15950,14 +15961,16 @@ DEFINE_OPERATOR(int, DelRangeEndIndex, (DeeObject *self, DeeObject *start, Dee_ssize_t end)) { LOAD_TP_SELF; if (DeeInt_Check(start)) { - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_delrange_index) || DeeType_InheritDelRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_delrange_index) || + unlikely(DeeType_InheritDelRange(tp_self))) { Dee_ssize_t start_index; if (DeeInt_AsSSize(start, &start_index)) goto err; return DeeType_INVOKE_DELRANGEINDEX(tp_self, self, start_index, end); } } else { - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_delrange) || DeeType_InheritDelRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_delrange) || + unlikely(DeeType_InheritDelRange(tp_self))) { int result; DREF DeeObject *end_ob = DeeInt_NewSSize(end); if unlikely(!end_ob) @@ -15975,7 +15988,8 @@ DEFINE_OPERATOR(int, DelRangeEndIndex, DEFINE_OPERATOR(int, DelRangeIndex, (DeeObject *RESTRICT_IF_NOTYPE self, Dee_ssize_t start, Dee_ssize_t end)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_delrange_index) || DeeType_InheritDelRange(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_delrange_index) || + unlikely(DeeType_InheritDelRange(tp_self))) return DeeType_INVOKE_DELRANGEINDEX(tp_self, self, start, end); return err_unimplemented_operator(tp_self, OPERATOR_DELRANGE); } @@ -15983,7 +15997,8 @@ DEFINE_OPERATOR(int, DelRangeIndex, DEFINE_OPERATOR(int, DelRangeIndexN, (DeeObject *RESTRICT_IF_NOTYPE self, Dee_ssize_t start)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_delrange_index_n) || DeeType_InheritDelRange(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_delrange_index_n) || + unlikely(DeeType_InheritDelRange(tp_self))) return DeeType_INVOKE_DELRANGEINDEXN(tp_self, self, start); return err_unimplemented_operator(tp_self, OPERATOR_DELRANGE); } @@ -15992,17 +16007,20 @@ DEFINE_OPERATOR(int, SetRangeBeginIndex, (DeeObject *self, Dee_ssize_t start, DeeObject *end, DeeObject *values)) { LOAD_TP_SELF; if (DeeNone_Check(end)) { - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_setrange_index_n) || DeeType_InheritSetRange(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_setrange_index_n) || + unlikely(DeeType_InheritSetRange(tp_self))) return DeeType_INVOKE_SETRANGEINDEXN(tp_self, self, start, values); } else if (DeeInt_Check(end)) { - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_setrange_index) || DeeType_InheritSetRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_setrange_index) || + unlikely(DeeType_InheritSetRange(tp_self))) { Dee_ssize_t end_index; if (DeeInt_AsSSize(end, &end_index)) goto err; return DeeType_INVOKE_SETRANGEINDEX(tp_self, self, start, end_index, values); } } else { - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_setrange) || DeeType_InheritSetRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_setrange) || + unlikely(DeeType_InheritSetRange(tp_self))) { int result; DREF DeeObject *start_ob = DeeInt_NewSSize(start); if unlikely(!start_ob) @@ -16021,14 +16039,16 @@ DEFINE_OPERATOR(int, SetRangeEndIndex, (DeeObject *self, DeeObject *start, Dee_ssize_t end, DeeObject *values)) { LOAD_TP_SELF; if (DeeInt_Check(start)) { - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_setrange_index) || DeeType_InheritSetRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_setrange_index) || + unlikely(DeeType_InheritSetRange(tp_self))) { Dee_ssize_t start_index; if (DeeInt_AsSSize(start, &start_index)) goto err; return DeeType_INVOKE_SETRANGEINDEX(tp_self, self, start_index, end, values); } } else { - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_setrange) || DeeType_InheritSetRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_setrange) || + unlikely(DeeType_InheritSetRange(tp_self))) { int result; DREF DeeObject *end_ob = DeeInt_NewSSize(end); if unlikely(!end_ob) @@ -16046,7 +16066,8 @@ DEFINE_OPERATOR(int, SetRangeEndIndex, DEFINE_OPERATOR(int, SetRangeIndex, (DeeObject *self, Dee_ssize_t start, Dee_ssize_t end, DeeObject *values)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_setrange_index) || DeeType_InheritSetRange(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_setrange_index) || + unlikely(DeeType_InheritSetRange(tp_self))) return DeeType_INVOKE_SETRANGEINDEX(tp_self, self, start, end, values); return err_unimplemented_operator(tp_self, OPERATOR_SETRANGE); } @@ -16054,7 +16075,8 @@ DEFINE_OPERATOR(int, SetRangeIndex, DEFINE_OPERATOR(int, SetRangeIndexN, (DeeObject *self, Dee_ssize_t start, DeeObject *values)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_setrange_index_n) || DeeType_InheritSetRange(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_setrange_index_n) || + unlikely(DeeType_InheritSetRange(tp_self))) return DeeType_INVOKE_SETRANGEINDEXN(tp_self, self, start, values); return err_unimplemented_operator(tp_self, OPERATOR_SETRANGE); } @@ -16064,8 +16086,8 @@ DEFINE_OPERATOR(DREF DeeObject *, GetRangeBeginIndex, (DeeObject *self, Dee_ssize_t begin, DeeObject *end)) { LOAD_TP_SELF; ASSERT_OBJECT(end); - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getrange) || - DeeType_InheritGetRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getrange) || + unlikely(DeeType_InheritGetRange(tp_self))) { Dee_ssize_t end_index; struct type_nsi const *nsi; DREF DeeObject *begin_ob, *result; @@ -16096,8 +16118,8 @@ DEFINE_OPERATOR(DREF DeeObject *, GetRangeBeginIndex, DEFINE_OPERATOR(DREF DeeObject *, GetRangeEndIndex, (DeeObject *self, DeeObject *begin, Dee_ssize_t end)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getrange) || - DeeType_InheritGetRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getrange) || + unlikely(DeeType_InheritGetRange(tp_self))) { Dee_ssize_t begin_index; DREF DeeObject *end_ob, *result; struct type_nsi const *nsi; @@ -16125,8 +16147,8 @@ DEFINE_OPERATOR(DREF DeeObject *, GetRangeEndIndex, DEFINE_OPERATOR(DREF DeeObject *, GetRangeIndex, (DeeObject *RESTRICT_IF_NOTYPE self, Dee_ssize_t begin, Dee_ssize_t end)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getrange) || - DeeType_InheritGetRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getrange) || + unlikely(DeeType_InheritGetRange(tp_self))) { DREF DeeObject *begin_ob, *end_ob, *result; struct type_nsi const *nsi; /* NSI optimizations. */ @@ -16157,8 +16179,8 @@ DEFINE_OPERATOR(int, DelRangeBeginIndex, (DeeObject *self, Dee_ssize_t begin, DeeObject *end)) { LOAD_TP_SELF; ASSERT_OBJECT(end); - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_delrange) || - DeeType_InheritSetRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_delrange) || + unlikely(DeeType_InheritSetRange(tp_self))) { int result; DREF DeeObject *begin_ob; struct type_nsi const *nsi; @@ -16191,8 +16213,8 @@ DEFINE_OPERATOR(int, DelRangeEndIndex, (DeeObject *self, DeeObject *begin, Dee_ssize_t end)) { LOAD_TP_SELF; ASSERT_OBJECT(begin); - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_delrange) || - DeeType_InheritSetRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_delrange) || + unlikely(DeeType_InheritSetRange(tp_self))) { int result; DREF DeeObject *end_ob; struct type_nsi const *nsi; @@ -16221,8 +16243,8 @@ DEFINE_OPERATOR(int, DelRangeEndIndex, DEFINE_OPERATOR(int, DelRangeIndex, (DeeObject *self, Dee_ssize_t begin, Dee_ssize_t end)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_delrange) || - DeeType_InheritSetRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_delrange) || + unlikely(DeeType_InheritSetRange(tp_self))) { DREF DeeObject *begin_ob, *end_ob; int result; struct type_nsi const *nsi; @@ -16255,8 +16277,8 @@ DEFINE_OPERATOR(int, SetRangeBeginIndex, LOAD_TP_SELF; ASSERT_OBJECT(end); ASSERT_OBJECT(values); - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_setrange) || - DeeType_InheritSetRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_setrange) || + unlikely(DeeType_InheritSetRange(tp_self))) { int result; DREF DeeObject *begin_ob; struct type_nsi const *nsi; @@ -16290,8 +16312,8 @@ DEFINE_OPERATOR(int, SetRangeEndIndex, LOAD_TP_SELF; ASSERT_OBJECT(begin); ASSERT_OBJECT(values); - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_setrange) || - DeeType_InheritSetRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_setrange) || + unlikely(DeeType_InheritSetRange(tp_self))) { int result; DREF DeeObject *end_ob; struct type_nsi const *nsi; @@ -16321,8 +16343,8 @@ DEFINE_OPERATOR(int, SetRangeIndex, (DeeObject *self, Dee_ssize_t begin, Dee_ssize_t end, DeeObject *values)) { LOAD_TP_SELF; ASSERT_OBJECT(values); - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_setrange) || - DeeType_InheritSetRange(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_setrange) || + unlikely(DeeType_InheritSetRange(tp_self))) { DREF DeeObject *begin_ob, *end_ob; int result; struct type_nsi const *nsi; @@ -16381,10 +16403,8 @@ DEFINE_OPERATOR(int, SetRangeIndexN, (DeeObject *self, Dee_ssize_t begin, DeeObj DEFINE_OPERATOR(int, DelRange, (DeeObject *self, DeeObject *start, DeeObject *end)) { LOAD_TP_SELF; - ASSERT_OBJECT(start); - ASSERT_OBJECT(end); - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_delrange) || - DeeType_InheritDelRange(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_delrange) || + unlikely(DeeType_InheritDelRange(tp_self))) return DeeType_INVOKE_DELRANGE(tp_self, self, start, end); return err_unimplemented_operator(tp_self, OPERATOR_DELRANGE); } @@ -16393,11 +16413,8 @@ DEFINE_OPERATOR(int, SetRange, (DeeObject *self, DeeObject *start, DeeObject *end, DeeObject *value)) { LOAD_TP_SELF; - ASSERT_OBJECT(start); - ASSERT_OBJECT(end); - ASSERT_OBJECT(value); - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_setrange) || - DeeType_InheritSetRange(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_setrange) || + unlikely(DeeType_InheritSetRange(tp_self))) return DeeType_INVOKE_SETRANGE(tp_self, self, start, end, value); return err_unimplemented_operator(tp_self, OPERATOR_SETRANGE); } @@ -16407,8 +16424,8 @@ DEFINE_OPERATOR(int, SetRange, #ifdef CONFIG_EXPERIMENTAL_NEW_SEQUENCE_OPERATORS DEFINE_OPERATOR(int, BoundItem, (DeeObject *self, DeeObject *index)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_bounditem) || - DeeType_InheritGetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_bounditem) || + unlikely(DeeType_InheritGetItem(tp_self))) return DeeType_INVOKE_BOUNDITEM(tp_self, self, index); return err_unimplemented_operator(tp_self, OPERATOR_GETITEM); } @@ -16416,32 +16433,36 @@ DEFINE_OPERATOR(int, BoundItem, (DeeObject *self, DeeObject *index)) { DEFINE_OPERATOR(int, BoundItemIndex, (DeeObject *RESTRICT_IF_NOTYPE self, size_t index)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_bounditem_index) || - DeeType_InheritGetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_bounditem_index) || + unlikely(DeeType_InheritGetItem(tp_self))) return DeeType_INVOKE_BOUNDITEMINDEX(tp_self, self, index); return err_unimplemented_operator(tp_self, OPERATOR_GETITEM); } DEFINE_OPERATOR(int, BoundItemStringHash, (DeeObject *self, char const *__restrict key, dhash_t hash)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_bounditem_string_hash) || - DeeType_InheritGetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_bounditem_string_hash) || + unlikely(DeeType_InheritGetItem(tp_self))) return DeeType_INVOKE_BOUNDITEMSTRINGHASH(tp_self, self, key, hash); return err_unimplemented_operator(tp_self, OPERATOR_GETITEM); } DEFINE_OPERATOR(int, BoundItemStringLenHash, (DeeObject *self, char const *__restrict key, size_t keylen, dhash_t hash)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_bounditem_string_len_hash) || - DeeType_InheritGetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_bounditem_string_len_hash) || + unlikely(DeeType_InheritGetItem(tp_self))) return DeeType_INVOKE_BOUNDITEMSTRINGLENHASH(tp_self, self, key, keylen, hash); return err_unimplemented_operator(tp_self, OPERATOR_GETITEM); } +/* Check if a given item exists (`deemon.hasitem(self, index)') + * @return: 1: Does exists + * @return: 0: Doesn't exist + * @return: -1: Error. */ DEFINE_OPERATOR(int, HasItem, (DeeObject *self, DeeObject *index)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_hasitem) || - DeeType_InheritGetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_hasitem) || + unlikely(DeeType_InheritGetItem(tp_self))) return DeeType_INVOKE_HASITEM(tp_self, self, index); return err_unimplemented_operator(tp_self, OPERATOR_GETITEM); } @@ -16449,32 +16470,32 @@ DEFINE_OPERATOR(int, HasItem, (DeeObject *self, DeeObject *index)) { DEFINE_OPERATOR(int, HasItemIndex, (DeeObject *RESTRICT_IF_NOTYPE self, size_t index)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_hasitem_index) || - DeeType_InheritGetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_hasitem_index) || + unlikely(DeeType_InheritGetItem(tp_self))) return DeeType_INVOKE_HASITEMINDEX(tp_self, self, index); return err_unimplemented_operator(tp_self, OPERATOR_GETITEM); } DEFINE_OPERATOR(int, HasItemStringHash, (DeeObject *self, char const *__restrict key, dhash_t hash)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_hasitem_string_hash) || - DeeType_InheritGetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_hasitem_string_hash) || + unlikely(DeeType_InheritGetItem(tp_self))) return DeeType_INVOKE_HASITEMSTRINGHASH(tp_self, self, key, hash); return err_unimplemented_operator(tp_self, OPERATOR_GETITEM); } DEFINE_OPERATOR(int, HasItemStringLenHash, (DeeObject *self, char const *__restrict key, size_t keylen, dhash_t hash)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_hasitem_string_len_hash) || - DeeType_InheritGetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_hasitem_string_len_hash) || + unlikely(DeeType_InheritGetItem(tp_self))) return DeeType_INVOKE_HASITEMSTRINGLENHASH(tp_self, self, key, keylen, hash); return err_unimplemented_operator(tp_self, OPERATOR_GETITEM); } DEFINE_OPERATOR(DREF DeeObject *, TryGetItem, (DeeObject *self, DeeObject *index)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_trygetitem) || - DeeType_InheritGetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_trygetitem) || + unlikely(DeeType_InheritGetItem(tp_self))) return DeeType_INVOKE_TRYGETITEM(tp_self, self, index); err_unimplemented_operator(tp_self, OPERATOR_GETITEM); return NULL; @@ -16483,8 +16504,8 @@ DEFINE_OPERATOR(DREF DeeObject *, TryGetItem, (DeeObject *self, DeeObject *index DEFINE_OPERATOR(DREF DeeObject *, TryGetItemIndex, (DeeObject *RESTRICT_IF_NOTYPE self, size_t index)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_trygetitem_index) || - DeeType_InheritGetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_trygetitem_index) || + unlikely(DeeType_InheritGetItem(tp_self))) return DeeType_INVOKE_TRYGETITEMINDEX(tp_self, self, index); err_unimplemented_operator(tp_self, OPERATOR_GETITEM); return NULL; @@ -16492,8 +16513,8 @@ DEFINE_OPERATOR(DREF DeeObject *, TryGetItemIndex, DEFINE_OPERATOR(DREF DeeObject *, TryGetItemStringHash, (DeeObject *self, char const *__restrict key, Dee_hash_t hash)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_trygetitem_string_hash) || - DeeType_InheritGetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_trygetitem_string_hash) || + unlikely(DeeType_InheritGetItem(tp_self))) return DeeType_INVOKE_TRYGETITEMSTRINGHASH(tp_self, self, key, hash); err_unimplemented_operator(tp_self, OPERATOR_GETITEM); return NULL; @@ -16501,71 +16522,18 @@ DEFINE_OPERATOR(DREF DeeObject *, TryGetItemStringHash, (DeeObject *self, char c DEFINE_OPERATOR(DREF DeeObject *, TryGetItemStringLenHash, (DeeObject *self, char const *__restrict key, size_t keylen, Dee_hash_t hash)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_trygetitem_string_len_hash) || - DeeType_InheritGetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_trygetitem_string_len_hash) || + unlikely(DeeType_InheritGetItem(tp_self))) return DeeType_INVOKE_TRYGETITEMSTRINGLENHASH(tp_self, self, key, keylen, hash); err_unimplemented_operator(tp_self, OPERATOR_GETITEM); return NULL; } -#ifndef DEFINE_TYPED_OPERATORS -DEFINE_OPERATOR(DREF DeeObject *, GetItemDef, (DeeObject *self, DeeObject *index, DeeObject *def)) { - LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_trygetitem) || - DeeType_InheritGetItem(tp_self)) { - DREF DeeObject *result; - result = DeeType_INVOKE_TRYGETITEM(tp_self, self, index); - if (result == ITER_DONE) { - result = def; - if (def != ITER_DONE) - Dee_Incref(def); - } - return result; - } - err_unimplemented_operator(tp_self, OPERATOR_GETITEM); - return NULL; -} - -DEFINE_OPERATOR(DREF DeeObject *, GetItemStringHashDef, (DeeObject *self, char const *__restrict key, Dee_hash_t hash, DeeObject *def)) { - LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_trygetitem_string_hash) || - DeeType_InheritGetItem(tp_self)) { - DREF DeeObject *result; - result = DeeType_INVOKE_TRYGETITEMSTRINGHASH(tp_self, self, key, hash); - if (result == ITER_DONE) { - result = def; - if (def != ITER_DONE) - Dee_Incref(def); - } - return result; - } - err_unimplemented_operator(tp_self, OPERATOR_GETITEM); - return NULL; -} - -DEFINE_OPERATOR(DREF DeeObject *, GetItemStringLenHashDef, (DeeObject *self, char const *__restrict key, size_t keylen, Dee_hash_t hash, DeeObject *def)) { - LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_trygetitem_string_len_hash) || - DeeType_InheritGetItem(tp_self)) { - DREF DeeObject *result; - result = DeeType_INVOKE_TRYGETITEMSTRINGLENHASH(tp_self, self, key, keylen, hash); - if (result == ITER_DONE) { - result = def; - if (def != ITER_DONE) - Dee_Incref(def); - } - return result; - } - err_unimplemented_operator(tp_self, OPERATOR_GETITEM); - return NULL; -} -#endif /* !DEFINE_TYPED_OPERATORS */ - DEFINE_OPERATOR(DREF DeeObject *, GetItemIndex, (DeeObject *RESTRICT_IF_NOTYPE self, size_t index)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getitem_index) || - DeeType_InheritGetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getitem_index) || + unlikely(DeeType_InheritGetItem(tp_self))) return DeeType_INVOKE_GETITEMINDEX(tp_self, self, index); err_unimplemented_operator(tp_self, OPERATOR_GETITEM); return NULL; @@ -16574,24 +16542,24 @@ DEFINE_OPERATOR(DREF DeeObject *, GetItemIndex, DEFINE_OPERATOR(int, DelItemIndex, (DeeObject *RESTRICT_IF_NOTYPE self, size_t index)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_delitem_index) || - DeeType_InheritDelItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_delitem_index) || + unlikely(DeeType_InheritDelItem(tp_self))) return DeeType_INVOKE_DELITEMINDEX(tp_self, self, index); return err_unimplemented_operator(tp_self, OPERATOR_DELITEM); } DEFINE_OPERATOR(int, SetItemIndex, (DeeObject *self, size_t index, DeeObject *value)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_setitem_index) || - DeeType_InheritSetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_setitem_index) || + unlikely(DeeType_InheritSetItem(tp_self))) return DeeType_INVOKE_SETITEMINDEX(tp_self, self, index, value); return err_unimplemented_operator(tp_self, OPERATOR_SETITEM); } DEFINE_OPERATOR(DREF DeeObject *, GetItemStringHash, (DeeObject *self, char const *__restrict key, Dee_hash_t hash)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getitem_string_hash) || - DeeType_InheritGetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getitem_string_hash) || + unlikely(DeeType_InheritGetItem(tp_self))) return DeeType_INVOKE_GETITEMSTRINGHASH(tp_self, self, key, hash); err_unimplemented_operator(tp_self, OPERATOR_GETITEM); return NULL; @@ -16599,8 +16567,8 @@ DEFINE_OPERATOR(DREF DeeObject *, GetItemStringHash, (DeeObject *self, char cons DEFINE_OPERATOR(DREF DeeObject *, GetItemStringLenHash, (DeeObject *self, char const *__restrict key, size_t keylen, Dee_hash_t hash)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getitem_string_len_hash) || - DeeType_InheritGetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getitem_string_len_hash) || + unlikely(DeeType_InheritGetItem(tp_self))) return DeeType_INVOKE_GETITEMSTRINGLENHASH(tp_self, self, key, keylen, hash); err_unimplemented_operator(tp_self, OPERATOR_GETITEM); return NULL; @@ -16608,32 +16576,32 @@ DEFINE_OPERATOR(DREF DeeObject *, GetItemStringLenHash, (DeeObject *self, char c DEFINE_OPERATOR(int, DelItemStringHash, (DeeObject *self, char const *__restrict key, dhash_t hash)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_delitem_string_hash) || - DeeType_InheritDelItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_delitem_string_hash) || + unlikely(DeeType_InheritDelItem(tp_self))) return DeeType_INVOKE_DELITEMSTRINGHASH(tp_self, self, key, hash); return err_unimplemented_operator(tp_self, OPERATOR_DELITEM); } DEFINE_OPERATOR(int, DelItemStringLenHash, (DeeObject *self, char const *__restrict key, size_t keylen, dhash_t hash)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_delitem_string_len_hash) || - DeeType_InheritDelItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_delitem_string_len_hash) || + unlikely(DeeType_InheritDelItem(tp_self))) return DeeType_INVOKE_DELITEMSTRINGLENHASH(tp_self, self, key, keylen, hash); return err_unimplemented_operator(tp_self, OPERATOR_DELITEM); } DEFINE_OPERATOR(int, SetItemStringHash, (DeeObject *self, char const *__restrict key, dhash_t hash, DeeObject *value)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_setitem_string_hash) || - DeeType_InheritSetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_setitem_string_hash) || + unlikely(DeeType_InheritSetItem(tp_self))) return DeeType_INVOKE_SETITEMSTRINGHASH(tp_self, self, key, hash, value); return err_unimplemented_operator(tp_self, OPERATOR_SETITEM); } DEFINE_OPERATOR(int, SetItemStringLenHash, (DeeObject *self, char const *__restrict key, size_t keylen, dhash_t hash, DeeObject *value)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_setitem_string_len_hash) || - DeeType_InheritSetItem(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_setitem_string_len_hash) || + unlikely(DeeType_InheritSetItem(tp_self))) return DeeType_INVOKE_SETITEMSTRINGLENHASH(tp_self, self, key, keylen, hash, value); return err_unimplemented_operator(tp_self, OPERATOR_SETITEM); } @@ -16643,8 +16611,8 @@ DEFINE_OPERATOR(int, BoundItem, (DeeObject *self, DeeObject *index)) { DREF DeeObject *result; size_t i; LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getitem) || - DeeType_InheritGetItem(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getitem) || + unlikely(DeeType_InheritGetItem(tp_self))) { struct type_nsi const *nsi; nsi = tp_self->tp_seq->tp_nsi; if (nsi) { @@ -16712,8 +16680,8 @@ DEFINE_OPERATOR(int, BoundItemIndex, (DeeObject *RESTRICT_IF_NOTYPE self, size_t index)) { DREF DeeObject *result, *index_ob; LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getitem) || - DeeType_InheritGetItem(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getitem) || + unlikely(DeeType_InheritGetItem(tp_self))) { struct type_nsi const *nsi; nsi = tp_self->tp_seq->tp_nsi; if (nsi) { @@ -16784,30 +16752,23 @@ DEFINE_OPERATOR(int, BoundItemIndex, DEFINE_OPERATOR(int, BoundItemStringHash, (DeeObject *self, char const *key, dhash_t hash)) { int result; DeeObject *orig_self = self; - DREF DeeObject *key_ob; + DREF DeeObject *keyob; LOAD_TP_SELF; /* Optimization for specific types. */ again: - if (tp_self == &DeeDict_Type) { - result = DeeDict_HasItemStringHash(self, key, hash); - goto handle_bool; - } else if (tp_self == &DeeSuper_Type) { + if (tp_self == &DeeSuper_Type) { tp_self = DeeSuper_TYPE(self); self = DeeSuper_SELF(self); goto again; } /* Fallback: create a temporary string object and use it for indexing. */ - key_ob = DeeString_NewWithHash(key, hash); - if unlikely(!key_ob) + keyob = DeeString_NewWithHash(key, hash); + if unlikely(!keyob) goto err; - result = DeeObject_BoundItem(orig_self, key_ob); - Dee_Decref(key_ob); - return result; -handle_bool: - if (!result) - result = -2; + result = DeeObject_BoundItem(orig_self, keyob); + Dee_Decref(keyob); return result; err: return -1; @@ -16817,42 +16778,39 @@ DEFINE_OPERATOR(int, BoundItemStringLenHash, (DeeObject *self, char const *key, size_t keylen, dhash_t hash)) { int result; DeeObject *orig_self = self; - DREF DeeObject *key_ob; + DREF DeeObject *keyob; LOAD_TP_SELF; /* Optimization for specific types. */ again: - if (tp_self == &DeeDict_Type) { - result = DeeDict_HasItemStringLenHash(self, key, keylen, hash); - goto handle_bool; - } else if (tp_self == &DeeSuper_Type) { + if (tp_self == &DeeSuper_Type) { tp_self = DeeSuper_TYPE(self); self = DeeSuper_SELF(self); goto again; } /* Fallback: create a temporary string object and use it for indexing. */ - key_ob = DeeString_NewSizedWithHash(key, keylen, hash); - if unlikely(!key_ob) + keyob = DeeString_NewSizedWithHash(key, keylen, hash); + if unlikely(!keyob) goto err; - result = DeeObject_BoundItem(orig_self, key_ob); - Dee_Decref(key_ob); - return result; -handle_bool: - if (!result) - result = -2; + result = DeeObject_BoundItem(orig_self, keyob); + Dee_Decref(keyob); return result; err: return -1; } +/* Check if a given item exists (`deemon.hasitem(self, index)') + * @return: 1: Does exists + * @return: 0: Doesn't exist + * @return: -1: Error. */ DEFINE_OPERATOR(int, HasItem, (DeeObject *self, DeeObject *index)) { DREF DeeObject *result; size_t i; LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getitem) || - DeeType_InheritGetItem(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getitem) || + unlikely(DeeType_InheritGetItem(tp_self))) { struct type_nsi const *nsi; nsi = tp_self->tp_seq->tp_nsi; if (nsi) { @@ -16903,8 +16861,8 @@ DEFINE_OPERATOR(int, HasItemIndex, (DeeObject *RESTRICT_IF_NOTYPE self, size_t index)) { DREF DeeObject *result, *index_ob; LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getitem) || - DeeType_InheritGetItem(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getitem) || + unlikely(DeeType_InheritGetItem(tp_self))) { struct type_nsi const *nsi; nsi = tp_self->tp_seq->tp_nsi; if (nsi) { @@ -16958,71 +16916,75 @@ DEFINE_OPERATOR(int, HasItemIndex, } DEFINE_OPERATOR(int, HasItemStringHash, (DeeObject *self, char const *key, dhash_t hash)) { - bool b_result; int result; DeeObject *orig_self = self; - DREF DeeObject *key_ob; + DREF DeeObject *keyob; LOAD_TP_SELF; /* Optimization for specific types. */ again: - if (tp_self == &DeeDict_Type) { - b_result = DeeDict_HasItemStringHash(self, key, hash); - goto handle_bool; - } else if (tp_self == &DeeSuper_Type) { + if (tp_self == &DeeSuper_Type) { tp_self = DeeSuper_TYPE(self); self = DeeSuper_SELF(self); goto again; } /* Fallback: create a temporary string object and use it for indexing. */ - key_ob = DeeString_NewWithHash(key, hash); - if unlikely(!key_ob) + keyob = DeeString_NewWithHash(key, hash); + if unlikely(!keyob) goto err; - result = DeeObject_HasItem(orig_self, key_ob); - Dee_Decref(key_ob); + result = DeeObject_HasItem(orig_self, keyob); + Dee_Decref(keyob); return result; -handle_bool: - return b_result ? 1 : 0; err: return -1; } DEFINE_OPERATOR(int, HasItemStringLenHash, (DeeObject *self, char const *key, size_t keylen, dhash_t hash)) { - bool b_result; int result; DeeObject *orig_self = self; - DREF DeeObject *key_ob; + DREF DeeObject *keyob; LOAD_TP_SELF; /* Optimization for specific types. */ again: - if (tp_self == &DeeDict_Type) { - b_result = DeeDict_HasItemStringLenHash(self, key, keylen, hash); - goto handle_bool; - } else if (tp_self == &DeeSuper_Type) { + if (tp_self == &DeeSuper_Type) { tp_self = DeeSuper_TYPE(self); self = DeeSuper_SELF(self); goto again; } /* Fallback: create a temporary string object and use it for indexing. */ - key_ob = DeeString_NewSizedWithHash(key, keylen, hash); - if unlikely(!key_ob) + keyob = DeeString_NewSizedWithHash(key, keylen, hash); + if unlikely(!keyob) goto err; - result = DeeObject_HasItem(orig_self, key_ob); - Dee_Decref(key_ob); + result = DeeObject_HasItem(orig_self, keyob); + Dee_Decref(keyob); return result; -handle_bool: - return b_result ? 1 : 0; err: return -1; } DEFINE_OPERATOR(DREF DeeObject *, TryGetItem, (DeeObject *self, DeeObject *key)) { + DREF DeeObject *result; LOAD_TP_SELF; - (void)tp_self; - return DeeObject_GetItemDef(self, key, ITER_DONE); + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getitem) || + unlikely(DeeType_InheritGetItem(tp_self))) { + struct type_nsi const *nsi; + nsi = tp_self->tp_seq->tp_nsi; + if (nsi && nsi->nsi_class == TYPE_SEQX_CLASS_MAP) { + if (nsi->nsi_maplike.nsi_getdefault) + return (*nsi->nsi_maplike.nsi_getdefault)(self, key, ITER_DONE); + } + result = DeeType_INVOKE_GETITEM(tp_self, self, key); + if unlikely(!result) { + if (DeeError_Catch(&DeeError_KeyError) || + DeeError_Catch(&DeeError_NotImplemented)) + return ITER_DONE; + } + return result; + } + return ITER_DONE; } DEFINE_OPERATOR(DREF DeeObject *, TryGetItemIndex, @@ -17045,106 +17007,44 @@ DEFINE_OPERATOR(DREF DeeObject *, TryGetItemIndex, DEFINE_OPERATOR(DREF DeeObject *, TryGetItemStringHash, (DeeObject *RESTRICT_IF_NOTYPE self, char const *key, Dee_hash_t hash)) { - LOAD_TP_SELF; - (void)tp_self; - return DeeObject_GetItemStringHashDef(self, key, hash, ITER_DONE); -} - -DEFINE_OPERATOR(DREF DeeObject *, TryGetItemStringLenHash, - (DeeObject *RESTRICT_IF_NOTYPE self, char const *key, size_t keylen, Dee_hash_t hash)) { - LOAD_TP_SELF; - (void)tp_self; - return DeeObject_GetItemStringLenHashDef(self, key, keylen, hash, ITER_DONE); -} - -#ifndef DEFINE_TYPED_OPERATORS -DEFINE_OPERATOR(DREF DeeObject *, GetItemDef, (DeeObject *self, DeeObject *key, DeeObject *def)) { - DREF DeeObject *result; - LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getitem) || - DeeType_InheritGetItem(tp_self)) { - struct type_nsi const *nsi; - nsi = tp_self->tp_seq->tp_nsi; - if (nsi && nsi->nsi_class == TYPE_SEQX_CLASS_MAP) { - if (nsi->nsi_maplike.nsi_getdefault) - return (*nsi->nsi_maplike.nsi_getdefault)(self, key, def); - } - result = DeeType_INVOKE_GETITEM(tp_self, self, key); - if unlikely(!result) { - if (DeeError_Catch(&DeeError_KeyError) || - DeeError_Catch(&DeeError_NotImplemented)) { - if (def != ITER_DONE) - Dee_Incref(def); - return def; - } - } - return result; - } - err_unimplemented_operator(tp_self, OPERATOR_GETITEM); - return NULL; -} - -DEFINE_OPERATOR(DREF DeeObject *, GetItemStringHashDef, - (DeeObject *self, char const *key, dhash_t hash, DeeObject *def)) { - DeeObject *orig_self = self; - DREF DeeObject *key_ob, *result; - LOAD_TP_SELF; - - /* Optimization for specific types. */ -again: - if (tp_self == &DeeDict_Type) { - return DeeDict_GetItemStringHashDef(self, key, hash, def); - } else if (tp_self == &DeeSuper_Type) { - tp_self = DeeSuper_TYPE(self); - self = DeeSuper_SELF(self); - goto again; - } - - /* Fallback: create a temporary string object and use it for indexing. */ - key_ob = DeeString_NewWithHash(key, hash); - if unlikely(!key_ob) + DREF DeeObject *result, *keyob; + keyob = DeeString_NewWithHash(key, hash); + if unlikely(!keyob) goto err; - result = DeeObject_GetItemDef(orig_self, key_ob, def); - Dee_Decref(key_ob); +#ifdef DEFINE_TYPED_OPERATORS + result = DeeObject_TTryGetItem(tp_self, self, keyob); +#else /* DEFINE_TYPED_OPERATORS */ + result = DeeObject_TryGetItem(self, keyob); +#endif /* !DEFINE_TYPED_OPERATORS */ + Dee_Decref(keyob); return result; err: return NULL; } -DEFINE_OPERATOR(DREF DeeObject *, GetItemStringLenHashDef, - (DeeObject *self, char const *key, size_t keylen, dhash_t hash, DeeObject *def)) { - DeeObject *orig_self = self; - DREF DeeObject *key_ob, *result; - LOAD_TP_SELF; - - /* Optimization for specific types. */ -again: - if (tp_self == &DeeDict_Type) { - return DeeDict_GetItemStringLenHashDef(self, key, keylen, hash, def); - } else if (tp_self == &DeeSuper_Type) { - tp_self = DeeSuper_TYPE(self); - self = DeeSuper_SELF(self); - goto again; - } - - /* Fallback: create a temporary string object and use it for indexing. */ - key_ob = DeeString_NewSizedWithHash(key, keylen, hash); - if unlikely(!key_ob) +DEFINE_OPERATOR(DREF DeeObject *, TryGetItemStringLenHash, + (DeeObject *RESTRICT_IF_NOTYPE self, char const *key, size_t keylen, Dee_hash_t hash)) { + DREF DeeObject *result, *keyob; + keyob = DeeString_NewSizedWithHash(key, keylen, hash); + if unlikely(!keyob) goto err; - result = DeeObject_GetItemDef(orig_self, key_ob, def); - Dee_Decref(key_ob); +#ifdef DEFINE_TYPED_OPERATORS + result = DeeObject_TTryGetItem(tp_self, self, keyob); +#else /* DEFINE_TYPED_OPERATORS */ + result = DeeObject_TryGetItem(self, keyob); +#endif /* !DEFINE_TYPED_OPERATORS */ + Dee_Decref(keyob); return result; err: return NULL; } -#endif /* !DEFINE_TYPED_OPERATORS */ DEFINE_OPERATOR(DREF DeeObject *, GetItemIndex, (DeeObject *RESTRICT_IF_NOTYPE self, size_t index)) { DREF DeeObject *index_ob, *result; LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_getitem) || - DeeType_InheritGetItem(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_getitem) || + unlikely(DeeType_InheritGetItem(tp_self))) { struct type_nsi const *nsi; nsi = tp_self->tp_seq->tp_nsi; if (nsi && nsi->nsi_class == TYPE_SEQX_CLASS_SEQ) { @@ -17170,8 +17070,8 @@ DEFINE_OPERATOR(int, DelItemIndex, DREF DeeObject *index_ob; int result; LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_delitem) || - DeeType_InheritDelItem(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_delitem) || + unlikely(DeeType_InheritDelItem(tp_self))) { struct type_nsi const *nsi; nsi = tp_self->tp_seq->tp_nsi; if (nsi && nsi->nsi_class == TYPE_SEQX_CLASS_SEQ) { @@ -17196,8 +17096,8 @@ DEFINE_OPERATOR(int, SetItemIndex, (DeeObject *self, size_t index, DeeObject *va DREF DeeObject *index_ob; int result; LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_setitem) || - DeeType_InheritSetItem(tp_self)) { + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_setitem) || + unlikely(DeeType_InheritSetItem(tp_self))) { struct type_nsi const *nsi; nsi = tp_self->tp_seq->tp_nsi; if (nsi && nsi->nsi_class == TYPE_SEQX_CLASS_SEQ) { @@ -17219,7 +17119,7 @@ DEFINE_OPERATOR(int, SetItemIndex, (DeeObject *self, size_t index, DeeObject *va } DEFINE_OPERATOR(DREF DeeObject *, GetItemStringHash, (DeeObject *self, char const *key, dhash_t hash)) { - DREF DeeObject *key_ob, *result; + DREF DeeObject *keyob, *result; LOAD_TP_SELF; /* Optimization for specific types. */ @@ -17248,11 +17148,11 @@ DEFINE_OPERATOR(DREF DeeObject *, GetItemStringHash, (DeeObject *self, char cons } /* Fallback: create a temporary string object and use it for indexing. */ - key_ob = DeeString_NewWithHash(key, hash); - if unlikely(!key_ob) + keyob = DeeString_NewWithHash(key, hash); + if unlikely(!keyob) goto err; - result = DeeObject_TGetItem(tp_self, self, key_ob); - Dee_Decref(key_ob); + result = DeeObject_TGetItem(tp_self, self, keyob); + Dee_Decref(keyob); return result; xincref_result_and_return: Dee_XIncref(result); @@ -17263,7 +17163,7 @@ DEFINE_OPERATOR(DREF DeeObject *, GetItemStringHash, (DeeObject *self, char cons DEFINE_OPERATOR(DREF DeeObject *, GetItemStringLenHash, (DeeObject *self, char const *key, size_t keylen, dhash_t hash)) { - DREF DeeObject *key_ob, *result; + DREF DeeObject *keyob, *result; LOAD_TP_SELF; /* Optimization for specific types. */ @@ -17292,11 +17192,11 @@ DEFINE_OPERATOR(DREF DeeObject *, GetItemStringLenHash, } /* Fallback: create a temporary string object and use it for indexing. */ - key_ob = DeeString_NewSizedWithHash(key, keylen, hash); - if unlikely(!key_ob) + keyob = DeeString_NewSizedWithHash(key, keylen, hash); + if unlikely(!keyob) goto err; - result = DeeObject_TGetItem(tp_self, self, key_ob); - Dee_Decref(key_ob); + result = DeeObject_TGetItem(tp_self, self, keyob); + Dee_Decref(keyob); return result; xincref_result_and_return: Dee_XIncref(result); @@ -17306,22 +17206,22 @@ DEFINE_OPERATOR(DREF DeeObject *, GetItemStringLenHash, } DEFINE_OPERATOR(int, DelItemStringHash, (DeeObject *self, char const *key, dhash_t hash)) { - DREF DeeObject *key_ob; + DREF DeeObject *keyob; int result; LOAD_TP_SELF; if (tp_self == &DeeDict_Type) return DeeDict_DelItemStringHash(self, key, hash); /* Fallback: create a temporary string object and use it for indexing. */ - key_ob = DeeString_NewWithHash(key, hash); - if unlikely(!key_ob) + keyob = DeeString_NewWithHash(key, hash); + if unlikely(!keyob) goto err; #ifdef DEFINE_TYPED_OPERATORS - result = DeeObject_TDelItem(tp_self, self, key_ob); + result = DeeObject_TDelItem(tp_self, self, keyob); #else /* DEFINE_TYPED_OPERATORS */ - result = DeeObject_DelItem(self, key_ob); + result = DeeObject_DelItem(self, keyob); #endif /* !DEFINE_TYPED_OPERATORS */ - Dee_Decref(key_ob); + Dee_Decref(keyob); return result; err: return -1; @@ -17329,22 +17229,22 @@ DEFINE_OPERATOR(int, DelItemStringHash, (DeeObject *self, char const *key, dhash DEFINE_OPERATOR(int, DelItemStringLenHash, (DeeObject *self, char const *key, size_t keylen, dhash_t hash)) { - DREF DeeObject *key_ob; + DREF DeeObject *keyob; int result; LOAD_TP_SELF; if (tp_self == &DeeDict_Type) return DeeDict_DelItemStringLenHash(self, key, keylen, hash); /* Fallback: create a temporary string object and use it for indexing. */ - key_ob = DeeString_NewSizedWithHash(key, keylen, hash); - if unlikely(!key_ob) + keyob = DeeString_NewSizedWithHash(key, keylen, hash); + if unlikely(!keyob) goto err; #ifdef DEFINE_TYPED_OPERATORS - result = DeeObject_TDelItem(tp_self, self, key_ob); + result = DeeObject_TDelItem(tp_self, self, keyob); #else /* DEFINE_TYPED_OPERATORS */ - result = DeeObject_DelItem(self, key_ob); + result = DeeObject_DelItem(self, keyob); #endif /* !DEFINE_TYPED_OPERATORS */ - Dee_Decref(key_ob); + Dee_Decref(keyob); return result; err: return -1; @@ -17352,22 +17252,22 @@ DEFINE_OPERATOR(int, DelItemStringLenHash, DEFINE_OPERATOR(int, SetItemStringHash, (DeeObject *self, char const *key, dhash_t hash, DeeObject *value)) { - DREF DeeObject *key_ob; + DREF DeeObject *keyob; int result; LOAD_TP_SELF; if (tp_self == &DeeDict_Type) return DeeDict_SetItemStringHash(self, key, hash, value); /* Fallback: create a temporary string object and use it for indexing. */ - key_ob = DeeString_NewWithHash(key, hash); - if unlikely(!key_ob) + keyob = DeeString_NewWithHash(key, hash); + if unlikely(!keyob) goto err; #ifdef DEFINE_TYPED_OPERATORS - result = DeeObject_TSetItem(tp_self, self, key_ob, value); + result = DeeObject_TSetItem(tp_self, self, keyob, value); #else /* DEFINE_TYPED_OPERATORS */ - result = DeeObject_SetItem(self, key_ob, value); + result = DeeObject_SetItem(self, keyob, value); #endif /* !DEFINE_TYPED_OPERATORS */ - Dee_Decref(key_ob); + Dee_Decref(keyob); return result; err: return -1; @@ -17375,22 +17275,22 @@ DEFINE_OPERATOR(int, SetItemStringHash, DEFINE_OPERATOR(int, SetItemStringLenHash, (DeeObject *self, char const *key, size_t keylen, dhash_t hash, DeeObject *value)) { - DREF DeeObject *key_ob; + DREF DeeObject *keyob; int result; LOAD_TP_SELF; if (tp_self == &DeeDict_Type) return DeeDict_SetItemStringLenHash(self, key, keylen, hash, value); /* Fallback: create a temporary string object and use it for indexing. */ - key_ob = DeeString_NewSizedWithHash(key, keylen, hash); - if unlikely(!key_ob) + keyob = DeeString_NewSizedWithHash(key, keylen, hash); + if unlikely(!keyob) goto err; #ifdef DEFINE_TYPED_OPERATORS - result = DeeObject_TSetItem(tp_self, self, key_ob, value); + result = DeeObject_TSetItem(tp_self, self, keyob, value); #else /* DEFINE_TYPED_OPERATORS */ - result = DeeObject_SetItem(self, key_ob, value); + result = DeeObject_SetItem(self, keyob, value); #endif /* !DEFINE_TYPED_OPERATORS */ - Dee_Decref(key_ob); + Dee_Decref(keyob); return result; err: return -1; @@ -17398,7 +17298,6 @@ DEFINE_OPERATOR(int, SetItemStringLenHash, #endif /* !CONFIG_EXPERIMENTAL_NEW_SEQUENCE_OPERATORS */ - #ifndef DEFINE_TYPED_OPERATORS INTDEF int DCALL none_i1(void *UNUSED(a)); @@ -17459,7 +17358,8 @@ DeeType_InheritWith(DeeTypeObject *__restrict self) { DEFINE_OPERATOR(int, Enter, (DeeObject *RESTRICT_IF_NOTYPE self)) { LOAD_TP_SELF; - if likely((tp_self->tp_with && tp_self->tp_with->tp_enter) || DeeType_InheritWith(tp_self)) + if likely(likely(tp_self->tp_with && tp_self->tp_with->tp_enter) || + unlikely(DeeType_InheritWith(tp_self))) return DeeType_INVOKE_ENTER(tp_self, self); return err_unimplemented_operator(tp_self, OPERATOR_ENTER); } @@ -17467,7 +17367,8 @@ DEFINE_OPERATOR(int, Enter, DEFINE_OPERATOR(int, Leave, (DeeObject *RESTRICT_IF_NOTYPE self)) { LOAD_TP_SELF; - if likely((tp_self->tp_with && tp_self->tp_with->tp_leave) || DeeType_InheritWith(tp_self)) + if likely(likely(tp_self->tp_with && tp_self->tp_with->tp_leave) || + unlikely(DeeType_InheritWith(tp_self))) return DeeType_INVOKE_LEAVE(tp_self, self); return err_unimplemented_operator(tp_self, OPERATOR_LEAVE); } @@ -17504,8 +17405,8 @@ DEFINE_OPERATOR(int, GetBuf, (DeeObject *RESTRICT_IF_NOTYPE self, ASSERTF(!(flags & ~(Dee_BUFFER_FWRITABLE)), "Unknown buffers flags in %x", flags); LOAD_TP_SELF; - if likely((tp_self->tp_buffer && tp_self->tp_buffer->tp_getbuf) || - DeeType_InheritBuffer(tp_self)) { + if likely(likely(tp_self->tp_buffer && tp_self->tp_buffer->tp_getbuf) || + unlikely(DeeType_InheritBuffer(tp_self))) { if unlikely((flags & Dee_BUFFER_FWRITABLE) && (tp_self->tp_buffer->tp_buffer_flags & Dee_BUFFER_TYPE_FREADONLY)) { DeeError_Throwf(&DeeError_BufferError, @@ -17550,8 +17451,8 @@ DEFINE_OPERATOR(void, PutBuf, DEFINE_OPERATOR(Dee_ssize_t, Foreach, (DeeObject *RESTRICT_IF_NOTYPE self, Dee_foreach_t proc, void *arg)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_foreach) || - DeeType_InheritIter(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_foreach) || + unlikely(DeeType_InheritIter(tp_self))) return (*tp_self->tp_seq->tp_foreach)(self, proc, arg); return err_unimplemented_operator(tp_self, OPERATOR_ITER); } @@ -17559,8 +17460,8 @@ DEFINE_OPERATOR(Dee_ssize_t, Foreach, DEFINE_OPERATOR(Dee_ssize_t, ForeachPair, (DeeObject *RESTRICT_IF_NOTYPE self, Dee_foreach_pair_t proc, void *arg)) { LOAD_TP_SELF; - if likely((tp_self->tp_seq && tp_self->tp_seq->tp_foreach_pair) || - DeeType_InheritIter(tp_self)) + if likely(likely(tp_self->tp_seq && tp_self->tp_seq->tp_foreach_pair) || + unlikely(DeeType_InheritIter(tp_self))) return (*tp_self->tp_seq->tp_foreach_pair)(self, proc, arg); return err_unimplemented_operator(tp_self, OPERATOR_ITER); } diff --git a/src/dex/_hostasm/generator-vstack-ex.c b/src/dex/_hostasm/generator-vstack-ex.c index 8844f2367..83ec55684 100644 --- a/src/dex/_hostasm/generator-vstack-ex.c +++ b/src/dex/_hostasm/generator-vstack-ex.c @@ -3996,11 +3996,20 @@ fg_vopsetattr(struct fungen *__restrict self) { } +PRIVATE WUNUSED NONNULL((1, 2, 3)) DREF DeeObject *DCALL /* TODO: Remove me and directly use `DeeObject_TryGetItem()' */ +deprecated_DeeObject_GetItemDef(DeeObject *self, DeeObject *key, DeeObject *def) { + DREF DeeObject *result = DeeObject_TryGetItem(self, key); + if (result == ITER_DONE) { + result = def; + Dee_Incref(result); + } + return result; +} /* seq, key_or_index, def -> result */ INTERN WUNUSED NONNULL((1)) int DCALL fg_vopgetitemdef(struct fungen *__restrict self) { - /* IMPORTANT: `def' is allowed to be `ITER_DONE', and `DeeObject_GetItemDef()' is allowed to return `ITER_DONE' */ + /* IMPORTANT: `def' is allowed to be `ITER_DONE', and `deprecated_DeeObject_GetItemDef()' is allowed to return `ITER_DONE' */ DeeTypeObject *seq_type; if unlikely(self->fg_state->ms_stackc < 3) return err_illegal_stack_effect(); @@ -4010,14 +4019,19 @@ fg_vopgetitemdef(struct fungen *__restrict self) { uintptr_t getitem_flags = DeeType_GetOperatorFlags(seq_type, OPERATOR_GETITEM); if ((getitem_flags & METHOD_FCONSTCALL) && fg_vallconst(self, 3)) { DREF DeeObject *result; - DeeObject *seq, *key_def[2]; - seq = memval_const_getobj(&fg_vtop(self)[-2]); - key_def[0] = memval_const_getobj(&fg_vtop(self)[-1]); - key_def[1] = memval_const_getobj(&fg_vtop(self)[-0]); - if (!DeeMethodFlags_VerifyConstCallCondition(getitem_flags, seq, 2, key_def, NULL)) { + DeeObject *seq, *key, *def; + seq = memval_const_getobj(&fg_vtop(self)[-2]); + key = memval_const_getobj(&fg_vtop(self)[-1]); + def = memval_const_getobj(&fg_vtop(self)[-0]); + if (!DeeMethodFlags_VerifyConstCallCondition(getitem_flags, seq, 1, &key, NULL)) { /* Not allowed */ } else { - result = DeeObject_GetItemDef(seq, key_def[0], key_def[1]); + result = DeeObject_TryGetItem(seq, key); + if (result == ITER_DONE) { + result = def; + if (result != ITER_DONE) + Dee_Incref(result); + } if likely(result != NULL) { if (result != ITER_DONE) { result = fg_inlineref(self, result); @@ -4064,7 +4078,7 @@ fg_vopgetitemdef(struct fungen *__restrict self) { } DO(fg_vnotoneref(self, 2)); /* seq, key_or_index, def */ DO(fg_vnotoneref_if_operator_at(self, OPERATOR_GETITEM, 3)); /* seq, key_or_index, def */ - return fg_vcallapi(self, &DeeObject_GetItemDef, VCALL_CC_OBJECT, 3); + return fg_vcallapi(self, &deprecated_DeeObject_GetItemDef, VCALL_CC_OBJECT, 3); err: return -1; } diff --git a/src/dex/collections/rangemap.c b/src/dex/collections/rangemap.c index 77881bf4b..8713a96b9 100644 --- a/src/dex/collections/rangemap.c +++ b/src/dex/collections/rangemap.c @@ -600,7 +600,7 @@ rangemap_getitem_def(DeeObject *self, DeeObject *key, DeeObject *defl) { PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL rangemap_contains(DeeObject *self, DeeObject *key) { DREF DeeObject *value; - value = DeeObject_GetItemDef(self, key, ITER_DONE); + value = DeeObject_TryGetItem(self, key); if (!ITER_ISOK(value)) { if (value == ITER_DONE) return_false; @@ -1156,7 +1156,14 @@ proxy_nsi_getsize(RangeMapProxy *__restrict self) { PRIVATE WUNUSED NONNULL((1, 2, 3)) DREF DeeObject *DCALL proxy_asmap_nsi_getdefault(RangeMapProxy *self, DeeObject *key, DeeObject *defl) { - return DeeObject_GetItemDef(self->rmp_rmap, key, defl); + DREF DeeObject *result; + result = DeeObject_TryGetItem(self->rmp_rmap, key); + if (result == ITER_DONE) { + result = defl; + if (result != ITER_DONE) + Dee_Incref(result); + } + return result; } PRIVATE WUNUSED NONNULL((1, 2, 3)) DREF DeeObject *DCALL