1 |
On Sat, Jan 28, 2006 at 02:39:42AM -0800, Zac Medico wrote: |
2 |
> def _delitem(self, cpv): |
3 |
> try: |
4 |
> del self.db_rw[cpv] |
5 |
> except KeyError, ke: |
6 |
> if not self.db_ro.has_key(cpv): |
7 |
> raise ke |
8 |
|
9 |
You need white outs here (lifting a unionfs term); this won't actually |
10 |
change state in any way if you're trying to delete a bad entry from |
11 |
the underlying metadata cache. |
12 |
|
13 |
> |
14 |
> def has_key(self, cpv): |
15 |
> return self.db_rw.has_key(cpv) or self.db_ro.has_key(cpv) |
16 |
> |
17 |
> def iterkeys(self): |
18 |
> s = set() |
19 |
> for db in (self.db_rw, self.db_ro): |
20 |
> for cpv in db.iterkeys(): |
21 |
> if cpv not in s: |
22 |
> yield cpv |
23 |
> s.add(cpv) |
24 |
Should just do |
25 |
s=set() |
26 |
for cpv in self.db_rw: |
27 |
yield cpv |
28 |
s.add(cpv) |
29 |
for cpv in self.db_ro: |
30 |
if cpv not in s: |
31 |
yield cpv |
32 |
|
33 |
|
34 |
Slightly faster (1us per yield for the set lookup), but mainly less |
35 |
memory usage. |
36 |
|
37 |
Aside from that, the label trick is icky. ;) |