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
77c43a1d
Commit
77c43a1d
authored
Dec 19, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
f25b51d4
77e515f5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
8 deletions
+59
-8
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+9
-1
Cython/Utility/arrayarray.h
Cython/Utility/arrayarray.h
+8
-6
tests/run/builtin_sorted.pyx
tests/run/builtin_sorted.pyx
+32
-1
tests/run/pyarray.pyx
tests/run/pyarray.pyx
+10
-0
No files found.
Cython/Compiler/Optimize.py
View file @
77c43a1d
...
...
@@ -1477,6 +1477,10 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
gen_expr_node
.
pos
,
loop
=
loop_node
,
result_node
=
result_ref
,
expr_scope
=
gen_expr_node
.
expr_scope
,
orig_func
=
is_any
and
'any'
or
'all'
)
PySequence_List_func_type
=
PyrexTypes
.
CFuncType
(
Builtin
.
list_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"it"
,
PyrexTypes
.
py_object_type
,
None
)])
def
_handle_simple_function_sorted
(
self
,
node
,
pos_args
):
"""Transform sorted(genexpr) and sorted([listcomp]) into
[listcomp].sort(). CPython just reads the iterable into a
...
...
@@ -1514,7 +1518,11 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
expr
=
pos_args
[
0
].
as_list
()
listcomp_node
=
loop_node
=
expr
else
:
return
node
# Interestingly, PySequence_List works on a lot of non-sequence
# things as well.
listcomp_node
=
loop_node
=
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
"PySequence_List"
,
self
.
PySequence_List_func_type
,
args
=
pos_args
,
is_temp
=
True
)
result_node
=
UtilNodes
.
ResultRefNode
(
pos
=
loop_node
.
pos
,
type
=
Builtin
.
list_type
,
may_hold_none
=
False
)
...
...
Cython/Utility/arrayarray.h
View file @
77c43a1d
...
...
@@ -121,13 +121,15 @@ static CYTHON_INLINE int resize(arrayobject *self, Py_ssize_t n) {
static
CYTHON_INLINE
int
resize_smart
(
arrayobject
*
self
,
Py_ssize_t
n
)
{
void
*
items
=
(
void
*
)
self
->
data
.
ob_item
;
Py_ssize_t
newsize
;
if
(
n
<
self
->
allocated
)
{
if
(
n
*
4
>
self
->
allocated
)
{
self
->
ob_size
=
n
;
return
0
;
}
if
(
n
<
self
->
ob_size
)
{
self
->
ob_size
=
n
;
return
0
;
}
newsize
=
n
+
(
n
/
2
)
+
1
;
if
(
newsize
<=
self
->
allocated
)
{
/* overflow */
PyErr_NoMemory
();
return
-
1
;
}
newsize
=
n
*
3
/
2
+
1
;
PyMem_Resize
(
items
,
char
,
(
size_t
)(
newsize
*
self
->
ob_descr
->
itemsize
));
if
(
items
==
NULL
)
{
PyErr_NoMemory
();
...
...
tests/run/builtin_sorted.pyx
View file @
77c43a1d
cimport
cython
def
generator
():
yield
2
yield
1
yield
3
def
returns_set
():
return
set
([
"foo"
,
"bar"
,
"baz"
])
def
returns_tuple
():
return
(
1
,
2
,
3
,
0
)
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
)
def
sorted_arg
(
x
):
"""
>>> a = [3, 2, 1]
>>> sorted_arg(a)
[1, 2, 3]
>>> a
[3, 2, 1]
>>> sorted(generator())
[1, 2, 3]
>>> sorted(returns_set())
['bar', 'baz', 'foo']
>>> sorted(returns_tuple())
[0, 1, 2, 3]
>>> sorted(object())
Traceback (most recent call last):
TypeError: 'object' object is not iterable
"""
return
sorted
(
x
)
#@cython.test_fail_if_path_exists("//GeneratorExpressionNode",
# "//ComprehensionNode//NoneCheckNode")
#@cython.test_assert_path_exists("//ComprehensionNode")
...
...
@@ -10,7 +41,7 @@ def sorted_genexp():
"""
return
sorted
(
i
*
i
for
i
in
range
(
10
,
0
,
-
1
))
#
@cython.test_assert_path_exists("//SimpleCallNode//SimpleCallNode")
@
cython
.
test_assert_path_exists
(
"//SimpleCallNode//SimpleCallNode"
)
def
sorted_list_of_range
():
"""
>>> sorted_list_of_range()
...
...
tests/run/pyarray.pyx
View file @
77c43a1d
...
...
@@ -105,6 +105,16 @@ def test_resize(a):
assert
len
(
cb
)
==
10
assert
cb
[
9
]
==
cb
[
-
1
]
==
cb
.
data
.
as_floats
[
9
]
==
9
def
test_resize_smart
(
a
):
"""
>>> a = array.array('d', [1, 2, 3])
>>> test_resize_smart(a)
2
"""
cdef
array
.
array
cb
=
array
.
copy
(
a
)
array
.
resize_smart
(
cb
,
2
)
return
len
(
cb
)
def
test_buffer
():
"""
>>> test_buffer()
...
...
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