Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(88662)

Side by Side Diff: Objects/bytesobject.c

Issue 13411: Hashable memoryviews
Patch Set: Created 7 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_sys.py ('k') | Objects/memoryobject.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* bytes object implementation */ 1 /* bytes object implementation */
2 2
3 #define PY_SSIZE_T_CLEAN 3 #define PY_SSIZE_T_CLEAN
4 4
5 #include "Python.h" 5 #include "Python.h"
6 6
7 #include "bytes_methods.h" 7 #include "bytes_methods.h"
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 static Py_ssize_t 10 static Py_ssize_t
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 } 853 }
854 result = c ? Py_True : Py_False; 854 result = c ? Py_True : Py_False;
855 out: 855 out:
856 Py_INCREF(result); 856 Py_INCREF(result);
857 return result; 857 return result;
858 } 858 }
859 859
860 static Py_hash_t 860 static Py_hash_t
861 bytes_hash(PyBytesObject *a) 861 bytes_hash(PyBytesObject *a)
862 { 862 {
863 register Py_ssize_t len; 863 if (a->ob_shash == -1) {
864 register unsigned char *p; 864 /* Can't fail */
865 register Py_uhash_t x; 865 a->ob_shash = _Py_HashBytes((unsigned char *) a->ob_sval, Py_SIZE(a));
866 866 }
867 if (a->ob_shash != -1) 867 return a->ob_shash;
868 return a->ob_shash;
869 len = Py_SIZE(a);
870 p = (unsigned char *) a->ob_sval;
871 x = (Py_uhash_t)*p << 7;
872 while (--len >= 0)
873 x = (1000003U*x) ^ (Py_uhash_t)*p++;
874 x ^= (Py_uhash_t)Py_SIZE(a);
875 if (x == -1)
876 x = -2;
877 a->ob_shash = x;
878 return x;
879 } 868 }
880 869
881 static PyObject* 870 static PyObject*
882 bytes_subscript(PyBytesObject* self, PyObject* item) 871 bytes_subscript(PyBytesObject* self, PyObject* item)
883 { 872 {
884 if (PyIndex_Check(item)) { 873 if (PyIndex_Check(item)) {
885 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); 874 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
886 if (i == -1 && PyErr_Occurred()) 875 if (i == -1 && PyErr_Occurred())
887 return NULL; 876 return NULL;
888 if (i < 0) 877 if (i < 0)
(...skipping 2241 matching lines...) Expand 10 before | Expand all | Expand 10 after
3130 } 3119 }
3131 it = PyObject_GC_New(striterobject, &PyBytesIter_Type); 3120 it = PyObject_GC_New(striterobject, &PyBytesIter_Type);
3132 if (it == NULL) 3121 if (it == NULL)
3133 return NULL; 3122 return NULL;
3134 it->it_index = 0; 3123 it->it_index = 0;
3135 Py_INCREF(seq); 3124 Py_INCREF(seq);
3136 it->it_seq = (PyBytesObject *)seq; 3125 it->it_seq = (PyBytesObject *)seq;
3137 _PyObject_GC_TRACK(it); 3126 _PyObject_GC_TRACK(it);
3138 return (PyObject *)it; 3127 return (PyObject *)it;
3139 } 3128 }
OLDNEW
« no previous file with comments | « Lib/test/test_sys.py ('k') | Objects/memoryobject.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+