Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
_add_wordinfo() and _mass_add_wordinfo(): it's never necessary to call
Browse files Browse the repository at this point in the history
len(IIBTree) in these guys, so don't.
  • Loading branch information
Tim Peters committed May 27, 2002
1 parent 64a0154 commit 1c6fa5e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions BaseIndex.py
Expand Up @@ -234,7 +234,11 @@ def _add_wordinfo(self, wid, f, docid):
else:
# _add_wordinfo() is called for each update. If the map
# size exceeds the DICT_CUTOFF, convert to an IIBTree.
if len(doc2score) == self.DICT_CUTOFF:
# Obscure: First check the type. If it's not a dict, it
# can't need conversion, and then we can avoid an expensive
# len(IIBTree).
if (isinstance(doc2score, type({})) and
len(doc2score) == self.DICT_CUTOFF):
doc2score = IIBTree(doc2score)
doc2score[docid] = f
self._wordinfo[wid] = doc2score # not redundant: Persistency!
Expand All @@ -248,14 +252,15 @@ def _add_wordinfo(self, wid, f, docid):
#
# except that _mass_add_wordinfo doesn't require so many function calls.
def _mass_add_wordinfo(self, wid2weight, docid):
dicttype = type({})
get_doc2score = self._wordinfo.get
for wid, weight in wid2weight.items():
doc2score = get_doc2score(wid)
if doc2score is None:
doc2score = {}
else:
if len(doc2score) == self.DICT_CUTOFF:
doc2score = IIBTree(doc2score)
elif (isinstance(doc2score, dicttype) and
len(doc2score) == self.DICT_CUTOFF):
doc2score = IIBTree(doc2score)
doc2score[docid] = weight
self._wordinfo[wid] = doc2score # not redundant: Persistency!

Expand Down

0 comments on commit 1c6fa5e

Please sign in to comment.