Skip to content

Commit 6c7bc79

Browse files
committed
deque: fix count method
- sys revert maxsize until PInt is supported by most builtins
1 parent 28c5754 commit 6c7bc79

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

graalpython/lib-graalpython/_collections.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, Oracle and/or its affiliates.
1+
# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
22
# Copyright (c) 2017, The PyPy Project
33
#
44
# The MIT License
@@ -20,6 +20,7 @@
2020
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2121
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2222
# DEALINGS IN THE SOFTWARE.
23+
2324
import sys
2425

2526

@@ -169,23 +170,29 @@ def clear(self):
169170
self.len = 0
170171
self._modified()
171172

172-
def count(self, x):
173+
def count(self, v):
173174
"""Return number of occurrences of value."""
174-
result = 0
175-
block = self.leftblock
175+
b = self.leftblock
176176
index = self.leftindex
177+
n = self.len
178+
count = 0
177179
lock = self._getlock()
178-
for i in range(self.len):
179-
w_item = block.data[index]
180-
if w_item == x:
181-
result += 1
180+
181+
while (n - 1) >= 0:
182+
n -= 1
183+
assert b is not None
184+
item = b.data[index]
185+
if item == v:
186+
count += 1
187+
182188
self._checklock(lock)
183-
# Advance the block/index pair
189+
184190
index += 1
185-
if index >= BLOCKLEN:
186-
block = block.rightlink
191+
if index == BLOCKLEN:
192+
b = b.rightlink
187193
index = 0
188-
return result
194+
195+
return count
189196

190197
def extend(self, iterable):
191198
"""Extend the right side of the deque with elements from the iterable"""

graalpython/lib-graalpython/sys.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,3 @@ def __print_traceback__(typ, value, tb):
169169
__excepthook__ = make_excepthook()
170170
excepthook = __excepthook__
171171
del make_excepthook
172-
173-
# TODO: this is really based on size_t but we do not have access to that one here,
174-
# so we hardcode it for the moment until a better way is found
175-
maxsize = ((2**64)-1) >> 1

0 commit comments

Comments
 (0)