@cryptotaxi247 / kubo / commits / fecfb76cd

pin: Remove double bookkeeping of refcount keys

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Tommi Virtanen committed May 8, 2015 at 17:10 UTC fecfb76cdf653a973048a7f5d2cacc7ed565e335
1 file changed +6 -14
pin/indirect.go
+6 -14
@@ -3,17 +3,14 @@ package pin
3 import (
4 ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
5 key "github.com/ipfs/go-ipfs/blocks/key"
6 - "github.com/ipfs/go-ipfs/blocks/set"
6 )
7
8 type indirectPin struct {
10 - blockset set.BlockSet
9 refCounts map[key.Key]int
10 }
11
12 func newIndirectPin() *indirectPin {
13 return &indirectPin{
16 - blockset: set.NewSimpleBlockSet(),
14 refCounts: make(map[key.Key]int),
15 }
16 }
@@ -36,7 +33,7 @@ func loadIndirPin(d ds.Datastore, k ds.Key) (*indirectPin, error) {
33 }
34 // log.Debugf("indirPin keys: %#v", keys)
35
39 - return &indirectPin{blockset: set.SimpleSetFromKeys(keys), refCounts: refcnt}, nil
36 + return &indirectPin{refCounts: refcnt}, nil
37 }
38
39 func storeIndirPin(d ds.Datastore, k ds.Key, p *indirectPin) error {
@@ -49,11 +46,7 @@ func storeIndirPin(d ds.Datastore, k ds.Key, p *indirectPin) error {
46 }
47
48 func (i *indirectPin) Increment(k key.Key) {
52 - c := i.refCounts[k]
53 - i.refCounts[k] = c + 1
54 - if c <= 0 {
55 - i.blockset.AddBlock(k)
56 - }
49 + i.refCounts[k]++
50 }
51
52 func (i *indirectPin) Decrement(k key.Key) {
@@ -61,16 +54,15 @@ func (i *indirectPin) Decrement(k key.Key) {
54 log.Warningf("pinning: bad call: asked to unpin nonexistent indirect key: %v", k)
55 return
56 }
64 - c := i.refCounts[k] - 1
65 - i.refCounts[k] = c
66 - if c <= 0 {
67 - i.blockset.RemoveBlock(k)
57 + i.refCounts[k]--
58 + if i.refCounts[k] == 0 {
59 delete(i.refCounts, k)
60 }
61 }
62
63 func (i *indirectPin) HasKey(k key.Key) bool {
73 - return i.blockset.HasKey(k)
64 + _, found := i.refCounts[k]
65 + return found
66 }
67
68 func (i *indirectPin) GetRefs() map[key.Key]int {