Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 25113:0ca8410ea345
util: drop alias for collections.deque
Now that util.deque is just an alias for collections.deque, let's just
remove it.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Sat, 16 May 2015 11:28:04 -0700 |
parents | 3d14c1217117 |
children | ac2e66f481c9 |
comparison
equal
deleted
inserted
replaced
25112:3d14c1217117 | 25113:0ca8410ea345 |
---|---|
332 cache[args] = func(*args) | 332 cache[args] = func(*args) |
333 return cache[args] | 333 return cache[args] |
334 | 334 |
335 return f | 335 return f |
336 | 336 |
337 deque = collections.deque | |
338 | |
339 class sortdict(dict): | 337 class sortdict(dict): |
340 '''a simple sorted dictionary''' | 338 '''a simple sorted dictionary''' |
341 def __init__(self, data=None): | 339 def __init__(self, data=None): |
342 self._list = [] | 340 self._list = [] |
343 if data: | 341 if data: |
384 class lrucachedict(object): | 382 class lrucachedict(object): |
385 '''cache most recent gets from or sets to this dictionary''' | 383 '''cache most recent gets from or sets to this dictionary''' |
386 def __init__(self, maxsize): | 384 def __init__(self, maxsize): |
387 self._cache = {} | 385 self._cache = {} |
388 self._maxsize = maxsize | 386 self._maxsize = maxsize |
389 self._order = deque() | 387 self._order = collections.deque() |
390 | 388 |
391 def __getitem__(self, key): | 389 def __getitem__(self, key): |
392 value = self._cache[key] | 390 value = self._cache[key] |
393 self._order.remove(key) | 391 self._order.remove(key) |
394 self._order.append(key) | 392 self._order.append(key) |
406 def __contains__(self, key): | 404 def __contains__(self, key): |
407 return key in self._cache | 405 return key in self._cache |
408 | 406 |
409 def clear(self): | 407 def clear(self): |
410 self._cache.clear() | 408 self._cache.clear() |
411 self._order = deque() | 409 self._order = collections.deque() |
412 | 410 |
413 def lrucachefunc(func): | 411 def lrucachefunc(func): |
414 '''cache most recent results of function calls''' | 412 '''cache most recent results of function calls''' |
415 cache = {} | 413 cache = {} |
416 order = deque() | 414 order = collections.deque() |
417 if func.func_code.co_argcount == 1: | 415 if func.func_code.co_argcount == 1: |
418 def f(arg): | 416 def f(arg): |
419 if arg not in cache: | 417 if arg not in cache: |
420 if len(cache) > 20: | 418 if len(cache) > 20: |
421 del cache[order.popleft()] | 419 del cache[order.popleft()] |
1189 yield chunk[pos:end] | 1187 yield chunk[pos:end] |
1190 pos = end | 1188 pos = end |
1191 else: | 1189 else: |
1192 yield chunk | 1190 yield chunk |
1193 self.iter = splitbig(in_iter) | 1191 self.iter = splitbig(in_iter) |
1194 self._queue = deque() | 1192 self._queue = collections.deque() |
1195 | 1193 |
1196 def read(self, l=None): | 1194 def read(self, l=None): |
1197 """Read L bytes of data from the iterator of chunks of data. | 1195 """Read L bytes of data from the iterator of chunks of data. |
1198 Returns less than L bytes if the iterator runs dry. | 1196 Returns less than L bytes if the iterator runs dry. |
1199 | 1197 |