Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Kirill Smelkov
Zope
Commits
7eedfdbc
Commit
7eedfdbc
authored
Aug 01, 2010
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Combine reverse and sort into one where possible
parent
d8557642
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
8 deletions
+12
-8
src/Products/ZCatalog/Catalog.py
src/Products/ZCatalog/Catalog.py
+6
-4
src/Products/ZCatalog/tests/test_catalog.py
src/Products/ZCatalog/tests/test_catalog.py
+6
-4
No files found.
src/Products/ZCatalog/Catalog.py
View file @
7eedfdbc
...
...
@@ -655,9 +655,10 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
append
((
k
,
intset
,
_self__getitem__
))
# Note that sort keys are unique.
result
.
sort
()
if
reverse
:
result
.
reverse
()
result
.
sort
(
reverse
=
True
)
else
:
result
.
sort
()
result
=
LazyCat
(
LazyValues
(
result
),
length
)
elif
limit
is
None
or
(
limit
*
4
>
rlen
):
# Iterate over the result set getting sort keys from the index
...
...
@@ -674,9 +675,10 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
# results with those of other catalogs while avoiding
# the cost of instantiating a LazyMap per result
if
merge
:
result
.
sort
()
if
reverse
:
result
.
reverse
()
result
.
sort
(
reverse
=
True
)
else
:
result
.
sort
()
if
limit
is
not
None
:
result
=
result
[:
limit
]
result
=
LazyValues
(
result
)
...
...
src/Products/ZCatalog/tests/test_catalog.py
View file @
7eedfdbc
...
...
@@ -46,9 +46,12 @@ def createDatabase():
app
=
createDatabase
()
def
sort
(
iterable
):
def
sort
(
iterable
,
reverse
=
False
):
L
=
list
(
iterable
)
L
.
sort
()
if
reverse
:
L
.
sort
(
reverse
=
True
)
else
:
L
.
sort
()
return
L
...
...
@@ -532,8 +535,7 @@ class TestMerge(CatalogBase, unittest.TestCase):
for
cat
in
self
.
catalogs
]
merged_rids
=
[
r
.
getRID
()
for
r
in
mergeResults
(
results
,
has_sort_keys
=
True
,
reverse
=
True
)]
expected
=
sort
(
chain
(
*
results
))
expected
.
reverse
()
expected
=
sort
(
chain
(
*
results
),
reverse
=
True
)
expected
=
[
rid
for
sortkey
,
rid
,
getitem
in
expected
]
self
.
assertEqual
(
merged_rids
,
expected
)
...
...
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