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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
472bcd7e
Commit
472bcd7e
authored
Nov 05, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inline PyObject_GetItem() for a ~10% speedup.
parent
7454b282
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
1 deletion
+49
-1
CHANGES.rst
CHANGES.rst
+2
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+4
-1
Cython/Utility/ObjectHandling.c
Cython/Utility/ObjectHandling.c
+43
-0
No files found.
CHANGES.rst
View file @
472bcd7e
...
...
@@ -18,6 +18,8 @@ Features added
* The new TSS C-API in CPython 3.7 is supported and has been backported.
Patch by Naotoshi Seo. (Github issue #1932)
* Subscripting (item access) is faster in some cases.
* Some ``bytearray`` operations have been optimised similar to ``bytes``.
* Safe integer loops (< range(2^30)) are optimised into C loops.
...
...
Cython/Compiler/ExprNodes.py
View file @
472bcd7e
...
...
@@ -3904,7 +3904,10 @@ class IndexNode(_IndexingBaseNode):
function
=
"__Pyx_PyObject_Dict_GetItem"
utility_code
=
UtilityCode
.
load_cached
(
"DictGetItem"
,
"ObjectHandling.c"
)
else
:
function
=
"PyObject_GetItem"
function
=
"__Pyx_PyObject_GetItem"
code
.
globalstate
.
use_utility_code
(
TempitaUtilityCode
.
load_cached
(
"GetItemInt"
,
"ObjectHandling.c"
))
utility_code
=
UtilityCode
.
load_cached
(
"ObjectGetItem"
,
"ObjectHandling.c"
)
elif
self
.
type
.
is_unicode_char
and
self
.
base
.
type
is
unicode_type
:
assert
self
.
index
.
type
.
is_int
function
=
"__Pyx_GetItemInt_Unicode"
...
...
Cython/Utility/ObjectHandling.c
View file @
472bcd7e
...
...
@@ -262,6 +262,49 @@ static CYTHON_INLINE int __Pyx_IterFinish(void) {
#endif
}
/////////////// ObjectGetItem.proto ///////////////
#if CYTHON_USE_TYPE_SLOTS
static
CYTHON_INLINE
PyObject
*
__Pyx_PyObject_GetItem
(
PyObject
*
obj
,
PyObject
*
key
);
/*proto*/
#else
#define __Pyx_PyObject_GetItem(obj, key) PyObject_GetItem(obj, key)
#endif
/////////////// ObjectGetItem ///////////////
// //@requires: GetItemInt - added in IndexNode as it uses templating.
#if CYTHON_USE_TYPE_SLOTS
static
PyObject
*
__Pyx_PyObject_GetIndex
(
PyObject
*
obj
,
PyObject
*
index
)
{
PySequenceMethods
*
m
=
Py_TYPE
(
obj
)
->
tp_as_sequence
;
if
(
likely
(
m
&&
m
->
sq_item
))
{
PyObject
*
runerr
;
Py_ssize_t
key_value
=
__Pyx_PyIndex_AsSsize_t
(
index
);
if
(
likely
(
key_value
!=
-
1
||
!
(
runerr
=
PyErr_Occurred
())))
{
return
__Pyx_GetItemInt_Fast
(
obj
,
key_value
,
0
,
1
,
1
);
}
// Error handling code -- only manage OverflowError differently.
if
(
PyErr_GivenExceptionMatches
(
runerr
,
PyExc_OverflowError
))
{
PyErr_Clear
();
PyErr_Format
(
PyExc_IndexError
,
"cannot fit '%.200s' into an index-sized integer"
,
Py_TYPE
(
index
)
->
tp_name
);
}
}
else
{
PyErr_Format
(
PyExc_TypeError
,
"'%.200s' object is not subscriptable"
,
Py_TYPE
(
obj
)
->
tp_name
);
}
return
NULL
;
}
static
PyObject
*
__Pyx_PyObject_GetItem
(
PyObject
*
obj
,
PyObject
*
key
)
{
PyMappingMethods
*
m
=
Py_TYPE
(
obj
)
->
tp_as_mapping
;
if
(
likely
(
m
&&
m
->
mp_subscript
))
{
return
m
->
mp_subscript
(
obj
,
key
);
}
return
__Pyx_PyObject_GetIndex
(
obj
,
key
);
}
#endif
/////////////// DictGetItem.proto ///////////////
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
...
...
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