From f240accde27bd0145587f4ceb7f6a640df95ae53 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 23 Jul 2020 18:53:52 -0700 Subject: [PATCH] Optimize id store Prefix() is now much faster than extracting the hash. This commit was moved from ipfs/go-ipfs-blockstore@8f7c32424c55e6e0cc75a7e743fddaf2329d583f --- blockstore/idstore.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/blockstore/idstore.go b/blockstore/idstore.go index 2a5bf8415..477da70b2 100644 --- a/blockstore/idstore.go +++ b/blockstore/idstore.go @@ -18,6 +18,11 @@ func NewIdStore(bs Blockstore) Blockstore { } func extractContents(k cid.Cid) (bool, []byte) { + // Pre-check by calling Prefix(), this much faster than extracting the hash. + if k.Prefix().MhType != mh.IDENTITY { + return false, nil + } + dmh, err := mh.Decode(k.Hash()) if err != nil || dmh.Code != mh.ID { return false, nil