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

Side by Side Diff: Objects/object.c

Issue 13411: Hashable memoryviews
Patch Set: Created 7 years, 9 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 | « Objects/memoryobject.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* Generic object operations; and implementation of None */ 2 /* Generic object operations; and implementation of None */
3 3
4 #include "Python.h" 4 #include "Python.h"
5 #include "frameobject.h" 5 #include "frameobject.h"
6 6
7 #ifdef __cplusplus 7 #ifdef __cplusplus
8 extern "C" { 8 extern "C" {
9 #endif 9 #endif
10 10
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 { 729 {
730 Py_hash_t x; 730 Py_hash_t x;
731 size_t y = (size_t)p; 731 size_t y = (size_t)p;
732 /* bottom 3 or 4 bits are likely to be 0; rotate y by 4 to avoid 732 /* bottom 3 or 4 bits are likely to be 0; rotate y by 4 to avoid
733 excessive hash collisions for dicts and sets */ 733 excessive hash collisions for dicts and sets */
734 y = (y >> 4) | (y << (8 * SIZEOF_VOID_P - 4)); 734 y = (y >> 4) | (y << (8 * SIZEOF_VOID_P - 4));
735 x = (Py_hash_t)y; 735 x = (Py_hash_t)y;
736 if (x == -1) 736 if (x == -1)
737 x = -2; 737 x = -2;
738 return x; 738 return x;
739 }
740
741 Py_hash_t
742 _Py_HashBytes(unsigned char *p, Py_ssize_t len)
743 {
744 register Py_uhash_t x;
745 register Py_ssize_t i;
746
747 x = (Py_uhash_t) *p << 7;
748 for (i = 0; i < len; i++)
749 x = (1000003U * x) ^ (Py_uhash_t) *p++;
750 x ^= (Py_uhash_t) len;
751 if (x == -1)
752 x = -2;
753 return x;
739 } 754 }
740 755
741 Py_hash_t 756 Py_hash_t
742 PyObject_HashNotImplemented(PyObject *v) 757 PyObject_HashNotImplemented(PyObject *v)
743 { 758 {
744 PyErr_Format(PyExc_TypeError, "unhashable type: '%.200s'", 759 PyErr_Format(PyExc_TypeError, "unhashable type: '%.200s'",
745 Py_TYPE(v)->tp_name); 760 Py_TYPE(v)->tp_name);
746 return -1; 761 return -1;
747 } 762 }
748 763
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1869 _Py_Dealloc(PyObject *op) 1884 _Py_Dealloc(PyObject *op)
1870 { 1885 {
1871 _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA 1886 _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA
1872 (*Py_TYPE(op)->tp_dealloc)(op); 1887 (*Py_TYPE(op)->tp_dealloc)(op);
1873 } 1888 }
1874 #endif 1889 #endif
1875 1890
1876 #ifdef __cplusplus 1891 #ifdef __cplusplus
1877 } 1892 }
1878 #endif 1893 #endif
OLDNEW
« no previous file with comments | « Objects/memoryobject.c ('k') | no next file » | no next file with comments »

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