Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
perf: remove manual enumerability modifications
Browse files Browse the repository at this point in the history
Instead of changing the enumerability of certain fields, just generate
the appropriate output of the `tree()` call. This is possible in dag-pb
as there are no user-defined dynamic fields that we might be able to
resolve into.

Closes #152.
  • Loading branch information
vmx committed Jul 19, 2019
1 parent a9aa0a0 commit 37ffdd5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 77 deletions.
5 changes: 0 additions & 5 deletions src/dag-link/dagLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const CID = require('cids')
const assert = require('assert')
const visibility = require('../visibility')
const withIs = require('class-is')

// Link represents an IPFS Merkle DAG Link between Nodes.
Expand All @@ -17,10 +16,6 @@ class DAGLink {
this._nameBuf = null
this._size = size
this._cid = new CID(cid)

// Make sure we have a nice public API that can be used by an IPLD resolver
visibility.hidePrivateFields(this)
visibility.addEnumerableGetters(this, ['Hash', 'Name', 'Tsize'])
}

toString () {
Expand Down
5 changes: 0 additions & 5 deletions src/dag-node/dagNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const withIs = require('class-is')
const sortLinks = require('./sortLinks')
const visibility = require('../visibility')
const DAGLink = require('../dag-link/dagLink')
const { serializeDAGNode } = require('../serialize.js')
const toDAGLink = require('./toDagLink')
Expand Down Expand Up @@ -38,10 +37,6 @@ class DAGNode {
this._data = data
this._links = links
this._serializedSize = serializedSize

// Make sure we have a nice public API that can be used by an IPLD resolver
visibility.hidePrivateFields(this)
visibility.addEnumerableGetters(this, ['Data', 'Links'])
}

toJSON () {
Expand Down
23 changes: 9 additions & 14 deletions src/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,6 @@ exports.resolve = (binaryBlob, path) => {
}
}

const traverse = function * (node, path) {
// Traverse only objects and arrays
if (Buffer.isBuffer(node) || CID.isCID(node) || typeof node === 'string' ||
node === null) {
return
}
for (const item of Object.keys(node)) {
const nextpath = path === undefined ? item : path + '/' + item
yield nextpath
yield * traverse(node[item], nextpath)
}
}

/**
* Return all available paths of a block.
*
Expand All @@ -77,5 +64,13 @@ const traverse = function * (node, path) {
exports.tree = function * (binaryBlob) {
const node = util.deserialize(binaryBlob)

yield * traverse(node)
// There is always a `Data` and `Links` property
yield 'Data'
yield 'Links'
for (let ii = 0; ii < node.Links.length; ii++) {
yield `Links/${ii}`
yield `Links/${ii}/Name`
yield `Links/${ii}/Tsize`
yield `Links/${ii}/Hash`
}
}
53 changes: 0 additions & 53 deletions src/visibility.js

This file was deleted.

0 comments on commit 37ffdd5

Please sign in to comment.