mirror of https://github.com/python/cpython
gh-107089: Improve Shelf.clear method performance (gh-107090)
This commit is contained in:
parent
11c055f5ff
commit
810d5d87d9
|
@ -226,6 +226,13 @@ class DbfilenameShelf(Shelf):
|
|||
import dbm
|
||||
Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
|
||||
|
||||
def clear(self):
|
||||
"""Remove all items from the shelf."""
|
||||
# Call through to the clear method on dbm-backed shelves.
|
||||
# see https://github.com/python/cpython/issues/107089
|
||||
self.cache.clear()
|
||||
self.dict.clear()
|
||||
|
||||
|
||||
def open(filename, flag='c', protocol=None, writeback=False):
|
||||
"""Open a persistent dictionary for reading and writing.
|
||||
|
|
|
@ -289,6 +289,7 @@ Edward Catmur
|
|||
Lorenzo M. Catucci
|
||||
Bruno Cauet
|
||||
Donn Cave
|
||||
James Cave
|
||||
Charles Cazabon
|
||||
Jesús Cea Avión
|
||||
Per Cederqvist
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Shelves opened with :func:`shelve.open` have a much faster :meth:`clear`
|
||||
method. Patch by James Cave.
|
Loading…
Reference in New Issue