Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
765d8f61
Commit
765d8f61
authored
Feb 22, 2010
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fast GetItem for declared dicts.
parent
86c65515
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
31 deletions
+70
-31
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+70
-31
No files found.
Cython/Compiler/ExprNodes.py
View file @
765d8f61
...
...
@@ -2036,7 +2036,11 @@ class IndexNode(ExprNode):
function
=
"__Pyx_GetItemInt"
code
.
globalstate
.
use_utility_code
(
getitem_int_utility_code
)
else
:
function
=
"PyObject_GetItem"
if
self
.
base
.
type
is
dict_type
:
function
=
"__Pyx_PyDict_GetItem"
code
.
globalstate
.
use_utility_code
(
getitem_dict_utility_code
)
else
:
function
=
"PyObject_GetItem"
index_code
=
self
.
index
.
py_result
()
sign_code
=
""
code
.
putln
(
...
...
@@ -6455,6 +6459,71 @@ impl = ""
#------------------------------------------------------------------------------------
raise_noneattr_error_utility_code
=
UtilityCode
(
proto
=
"""
static CYTHON_INLINE void __Pyx_RaiseNoneAttributeError(const char* attrname);
"""
,
impl
=
'''
static CYTHON_INLINE void __Pyx_RaiseNoneAttributeError(const char* attrname) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", attrname);
}
'''
)
raise_noneindex_error_utility_code
=
UtilityCode
(
proto
=
"""
static CYTHON_INLINE void __Pyx_RaiseNoneIndexingError(void);
"""
,
impl
=
'''
static CYTHON_INLINE void __Pyx_RaiseNoneIndexingError(void) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is unsubscriptable");
}
'''
)
raise_none_iter_error_utility_code
=
UtilityCode
(
proto
=
"""
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);
"""
,
impl
=
'''
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}
'''
)
#------------------------------------------------------------------------------------
getitem_dict_utility_code
=
UtilityCode
(
proto
=
"""
static PyObject *__Pyx_PyDict_GetItem(PyObject *o, PyObject* key) {
long hash;
PyDictEntry *entry;
PyObject *value;
if (unlikely(o == Py_None)) {
__Pyx_RaiseNoneIndexingError();
return NULL;
}
if (!PyString_CheckExact(key) ||
(hash = ((PyStringObject *) key)->ob_shash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1) return NULL;
}
entry = ((PyDictObject*)o)->ma_lookup((PyDictObject*)o, key, hash);
if (likely(entry != NULL)) {
value = entry->me_value;
if (likely(value != NULL)) {
Py_INCREF(value);
return value;
} else {
PyErr_SetObject(PyExc_KeyError, key);
}
}
return NULL;
}
"""
,
requires
=
[
raise_noneindex_error_utility_code
])
#------------------------------------------------------------------------------------
# If the is_unsigned flag is set, we need to do some extra work to make
# sure the index doesn't become negative.
...
...
@@ -6585,36 +6654,6 @@ impl = """
#------------------------------------------------------------------------------------
raise_noneattr_error_utility_code
=
UtilityCode
(
proto
=
"""
static CYTHON_INLINE void __Pyx_RaiseNoneAttributeError(const char* attrname);
"""
,
impl
=
'''
static CYTHON_INLINE void __Pyx_RaiseNoneAttributeError(const char* attrname) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", attrname);
}
'''
)
raise_noneindex_error_utility_code
=
UtilityCode
(
proto
=
"""
static CYTHON_INLINE void __Pyx_RaiseNoneIndexingError(void);
"""
,
impl
=
'''
static CYTHON_INLINE void __Pyx_RaiseNoneIndexingError(void) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is unsubscriptable");
}
'''
)
raise_none_iter_error_utility_code
=
UtilityCode
(
proto
=
"""
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);
"""
,
impl
=
'''
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}
'''
)
raise_too_many_values_to_unpack
=
UtilityCode
(
proto
=
"""
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(void);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment