[Python-checkins] cpython: dk_get_index/dk_set_index uses a type indices variable

victor.stinner python-checkins at python.org
Thu Sep 8 15:03:10 EDT 2016


https://hg.python.org/cpython/rev/48a1f97d03b4
changeset:   103344:48a1f97d03b4
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Thu Sep 08 11:35:46 2016 -0700
summary:
  dk_get_index/dk_set_index uses a type indices variable

Issue #27350.

files:
  Objects/dictobject.c |  24 ++++++++++++++++--------
  1 files changed, 16 insertions(+), 8 deletions(-)


diff --git a/Objects/dictobject.c b/Objects/dictobject.c
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -307,18 +307,22 @@
     Py_ssize_t ix;
 
     if (s <= 0xff) {
-        ix = ((char*) &keys->dk_indices[0])[i];
+        char *indices = (char*)keys->dk_indices;
+        ix = indices[i];
     }
     else if (s <= 0xffff) {
-        ix = ((int16_t*)&keys->dk_indices[0])[i];
+        int16_t *indices = (int16_t*)keys->dk_indices;
+        ix = indices[i];
     }
 #if SIZEOF_VOID_P > 4
     else if (s <= 0xffffffff) {
-        ix = ((int32_t*)&keys->dk_indices[0])[i];
+        int32_t *indices = (int32_t*)keys->dk_indices;
+        ix = indices[i];
     }
 #endif
     else {
-        ix = ((Py_ssize_t*)&keys->dk_indices[0])[i];
+        Py_ssize_t *indices = (Py_ssize_t*)keys->dk_indices;
+        ix = indices[i];
     }
     assert(ix >= DKIX_DUMMY);
     return ix;
@@ -333,21 +337,25 @@
     assert(ix >= DKIX_DUMMY);
 
     if (s <= 0xff) {
+        char *indices = (char*)keys->dk_indices;
         assert(ix <= 0x7f);
-        ((char*) &keys->dk_indices[0])[i] = (char)ix;
+        indices[i] = (char)ix;
     }
     else if (s <= 0xffff) {
+        int16_t *indices = (int16_t*)keys->dk_indices;
         assert(ix <= 0x7fff);
-        ((int16_t*) &keys->dk_indices[0])[i] = (int16_t)ix;
+        indices[i] = (int16_t)ix;
     }
 #if SIZEOF_VOID_P > 4
     else if (s <= 0xffffffff) {
+        int32_t *indices = (int32_t*)keys->dk_indices;
         assert(ix <= 0x7fffffff);
-        ((int32_t*) &keys->dk_indices[0])[i] = (int32_t)ix;
+        indices[i] = (int32_t)ix;
     }
 #endif
     else {
-        ((Py_ssize_t*) &keys->dk_indices[0])[i] = ix;
+        Py_ssize_t *indices = (Py_ssize_t*)keys->dk_indices;
+        indices[i] = ix;
     }
 }
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list