summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-06-10 07:46:01 (GMT)
committerGitHub <noreply@github.com>2021-06-10 07:46:01 (GMT)
commite117c0283705943189e6b1aef668a1f68f3f00a4 (patch)
tree2f0ed87b3a6ee853b65b7db260b39d62337e87bd /Objects
parent309ab616020f8504ced8ca64f7d7abc2df25a37f (diff)
downloadcpython-e117c0283705943189e6b1aef668a1f68f3f00a4.zip
cpython-e117c0283705943189e6b1aef668a1f68f3f00a4.tar.gz
cpython-e117c0283705943189e6b1aef668a1f68f3f00a4.tar.bz2
bpo-44337: Port LOAD_ATTR to PEP 659 adaptive interpreter (GH-26595)
* Specialize LOAD_ATTR with LOAD_ATTR_SLOT and LOAD_ATTR_SPLIT_KEYS * Move dict-common.h to internal/pycore_dict.h * Add LOAD_ATTR_WITH_HINT specialized opcode. * Quicken in function if loopy * Specialize LOAD_ATTR for module attributes. * Add specialization stats
Diffstat (limited to 'Objects')
-rw-r--r--Objects/dict-common.h65
-rw-r--r--Objects/dictobject.c22
-rw-r--r--Objects/odictobject.c2
3 files changed, 3 insertions, 86 deletions
diff --git a/Objects/dict-common.h b/Objects/dict-common.h
deleted file mode 100644
index a6f518f..0000000
--- a/Objects/dict-common.h
+++ /dev/null
@@ -1,65 +0,0 @@
-#ifndef Py_DICT_COMMON_H
-#define Py_DICT_COMMON_H
-
-typedef struct {
- /* Cached hash code of me_key. */
- Py_hash_t me_hash;
- PyObject *me_key;
- PyObject *me_value; /* This field is only meaningful for combined tables */
-} PyDictKeyEntry;
-
-/* _Py_dict_lookup() returns index of entry which can be used like DK_ENTRIES(dk)[index].
- * -1 when no entry found, -3 when compare raises error.
- */
-Py_ssize_t _Py_dict_lookup(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject **value_addr);
-
-
-#define DKIX_EMPTY (-1)
-#define DKIX_DUMMY (-2) /* Used internally */
-#define DKIX_ERROR (-3)
-
-typedef enum {
- DICT_KEYS_GENERAL = 0,
- DICT_KEYS_UNICODE = 1,
- DICT_KEYS_SPLIT = 2
-} DictKeysKind;
-
-/* See dictobject.c for actual layout of DictKeysObject */
-struct _dictkeysobject {
- Py_ssize_t dk_refcnt;
-
- /* Size of the hash table (dk_indices). It must be a power of 2. */
- uint8_t dk_log2_size;
-
- /* Kind of keys */
- uint8_t dk_kind;
-
- /* Version number -- Reset to 0 by any modification to keys */
- uint32_t dk_version;
-
- /* Number of usable entries in dk_entries. */
- Py_ssize_t dk_usable;
-
- /* Number of used entries in dk_entries. */
- Py_ssize_t dk_nentries;
-
- /* Actual hash table of dk_size entries. It holds indices in dk_entries,
- or DKIX_EMPTY(-1) or DKIX_DUMMY(-2).
-
- Indices must be: 0 <= indice < USABLE_FRACTION(dk_size).
-
- The size in bytes of an indice depends on dk_size:
-
- - 1 byte if dk_size <= 0xff (char*)
- - 2 bytes if dk_size <= 0xffff (int16_t*)
- - 4 bytes if dk_size <= 0xffffffff (int32_t*)
- - 8 bytes otherwise (int64_t*)
-
- Dynamically sized, SIZEOF_VOID_P is minimum. */
- char dk_indices[]; /* char is required to avoid strict aliasing. */
-
- /* "PyDictKeyEntry dk_entries[dk_usable];" array follows:
- see the DK_ENTRIES() macro */
-};
-
-#endif
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index d97f9e21..3a1dbc9 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -117,7 +117,7 @@ converting the dict to the combined table.
#include "pycore_object.h" // _PyObject_GC_TRACK()
#include "pycore_pyerrors.h" // _PyErr_Fetch()
#include "pycore_pystate.h" // _PyThreadState_GET()
-#include "dict-common.h"
+#include "pycore_dict.h"
#include "stringlib/eq.h" // unicode_eq()
/*[clinic input]
@@ -285,24 +285,6 @@ _PyDict_DebugMallocStats(FILE *out)
state->numfree, sizeof(PyDictObject));
}
-#define DK_LOG_SIZE(dk) ((dk)->dk_log2_size)
-#if SIZEOF_VOID_P > 4
-#define DK_SIZE(dk) (((int64_t)1)<<DK_LOG_SIZE(dk))
-#define DK_IXSIZE(dk) \
- (DK_LOG_SIZE(dk) <= 7 ? \
- 1 : DK_LOG_SIZE(dk) <= 15 ? \
- 2 : DK_LOG_SIZE(dk) <= 31 ? \
- 4 : sizeof(int64_t))
-#else
-#define DK_SIZE(dk) (1<<DK_LOG_SIZE(dk))
-#define DK_IXSIZE(dk) \
- (DK_LOG_SIZE(dk) <= 7 ? \
- 1 : DK_LOG_SIZE(dk) <= 15 ? \
- 2 : sizeof(int32_t))
-#endif
-#define DK_ENTRIES(dk) \
- ((PyDictKeyEntry*)(&((int8_t*)((dk)->dk_indices))[DK_SIZE(dk) * DK_IXSIZE(dk)]))
-
#define DK_MASK(dk) (DK_SIZE(dk)-1)
#define IS_POWER_OF_2(x) (((x) & (x-1)) == 0)
@@ -1544,10 +1526,10 @@ delitem_common(PyDictObject *mp, Py_hash_t hash, Py_ssize_t ix,
assert(hashpos >= 0);
mp->ma_used--;
+ mp->ma_keys->dk_version = 0;
mp->ma_version_tag = DICT_NEXT_VERSION();
ep = &DK_ENTRIES(mp->ma_keys)[ix];
dictkeys_set_index(mp->ma_keys, hashpos, DKIX_DUMMY);
- mp->ma_keys->dk_version = 0;
old_key = ep->me_key;
ep->me_key = NULL;
ep->me_value = NULL;
diff --git a/Objects/odictobject.c b/Objects/odictobject.c
index 6a33910..fb1ac0c 100644
--- a/Objects/odictobject.c
+++ b/Objects/odictobject.c
@@ -467,7 +467,7 @@ later:
#include "Python.h"
#include "pycore_object.h"
#include <stddef.h> // offsetof()
-#include "dict-common.h"
+#include "pycore_dict.h"
#include <stddef.h>
#include "clinic/odictobject.c.h"