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
99e88d36
Commit
99e88d36
authored
Apr 18, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avoid None check in __Pyx_PyDict_GetItem() when possible
parent
9789f14e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
10 deletions
+24
-10
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+2
-0
Cython/Utility/ObjectHandling.c
Cython/Utility/ObjectHandling.c
+0
-5
tests/run/dict_getitem.pyx
tests/run/dict_getitem.pyx
+22
-5
No files found.
Cython/Compiler/ExprNodes.py
View file @
99e88d36
...
@@ -2685,6 +2685,8 @@ class IndexNode(ExprNode):
...
@@ -2685,6 +2685,8 @@ class IndexNode(ExprNode):
elif
is_slice
and
base_type
in
(
bytes_type
,
str_type
,
unicode_type
,
list_type
,
tuple_type
):
elif
is_slice
and
base_type
in
(
bytes_type
,
str_type
,
unicode_type
,
list_type
,
tuple_type
):
self
.
type
=
base_type
self
.
type
=
base_type
else
:
else
:
if
base_type
is
dict_type
:
self
.
base
=
self
.
base
.
as_none_safe_node
(
"'NoneType' object is unsubscriptable"
)
self
.
type
=
py_object_type
self
.
type
=
py_object_type
else
:
else
:
if
base_type
.
is_ptr
or
base_type
.
is_array
:
if
base_type
.
is_ptr
or
base_type
.
is_array
:
...
...
Cython/Utility/ObjectHandling.c
View file @
99e88d36
...
@@ -236,15 +236,10 @@ static CYTHON_INLINE int __Pyx_IterFinish(void) {
...
@@ -236,15 +236,10 @@ static CYTHON_INLINE int __Pyx_IterFinish(void) {
}
}
/////////////// DictGetItem.proto ///////////////
/////////////// DictGetItem.proto ///////////////
//@requires: RaiseNoneIndexingError
#if PY_MAJOR_VERSION >= 3
#if PY_MAJOR_VERSION >= 3
static
PyObject
*
__Pyx_PyDict_GetItem
(
PyObject
*
d
,
PyObject
*
key
)
{
static
PyObject
*
__Pyx_PyDict_GetItem
(
PyObject
*
d
,
PyObject
*
key
)
{
PyObject
*
value
;
PyObject
*
value
;
if
(
unlikely
(
d
==
Py_None
))
{
__Pyx_RaiseNoneIndexingError
();
return
NULL
;
}
value
=
PyDict_GetItemWithError
(
d
,
key
);
value
=
PyDict_GetItemWithError
(
d
,
key
);
if
(
unlikely
(
!
value
))
{
if
(
unlikely
(
!
value
))
{
if
(
!
PyErr_Occurred
())
if
(
!
PyErr_Occurred
())
...
...
tests/run/dict_getitem.pyx
View file @
99e88d36
# mode: run
# tag: dict, getitem
cimport
cython
def
test
(
dict
d
,
index
):
def
test
(
dict
d
,
index
):
"""
"""
>>> d = { 1: 10 }
>>> d = { 1: 10 }
...
@@ -25,11 +30,6 @@ def test(dict d, index):
...
@@ -25,11 +30,6 @@ def test(dict d, index):
"""
"""
return
d
[
index
]
return
d
[
index
]
cdef
class
Subscriptable
:
def
__getitem__
(
self
,
key
):
return
key
def
getitem_in_condition
(
dict
d
,
key
,
expected_result
):
def
getitem_in_condition
(
dict
d
,
key
,
expected_result
):
"""
"""
>>> d = dict(a=1, b=2)
>>> d = dict(a=1, b=2)
...
@@ -37,3 +37,20 @@ def getitem_in_condition(dict d, key, expected_result):
...
@@ -37,3 +37,20 @@ def getitem_in_condition(dict d, key, expected_result):
True
True
"""
"""
return
d
[
key
]
is
expected_result
or
d
[
key
]
==
expected_result
return
d
[
key
]
is
expected_result
or
d
[
key
]
==
expected_result
@
cython
.
test_fail_if_path_exists
(
'//NoneCheckNode'
)
def
getitem_not_none
(
dict
d
not
None
,
key
):
"""
>>> d = { 1: 10 }
>>> test(d, 1)
10
>>> test(d, 2)
Traceback (most recent call last):
KeyError: 2
>>> test(d, (1,2))
Traceback (most recent call last):
KeyError: (1, 2)
"""
return
d
[
key
]
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