Skip to content

Commit

Permalink
First pass at addressing performance issues with #82
Browse files Browse the repository at this point in the history
See #87
  • Loading branch information
whitlockjc committed Jun 15, 2016
1 parent 6772c82 commit 5ad1f63
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
4 changes: 2 additions & 2 deletions browser/json-refs-min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions browser/json-refs-standalone-min.js

Large diffs are not rendered by default.

19 changes: 13 additions & 6 deletions browser/json-refs-standalone.js

Large diffs are not rendered by default.

19 changes: 13 additions & 6 deletions browser/json-refs.js

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,20 +318,28 @@ function findRefsRecursive (obj, options, parents, parentPtrs, allRefs, indirect
.then(function () {
// Identify indirect, local circular references (Issue 82)
var circulars = [];
var processedRefPtrs = [];
var processedRefs = [];

function walkRefs (parentPtrs, parentRefs, refPtr, ref) {
Object.keys(allRefs.refs).forEach(function (dRefPtr) {
var dRefDetails = allRefs.refs[dRefPtr];

// Do not process already processed references or references that are not a nested references
if (dRefPtr !== refPtr && dRefPtr.indexOf(ref + '/') === 0) {
if (processedRefs.indexOf(ref) === -1 && processedRefPtrs.indexOf(refPtr) === -1 &&
circulars.indexOf(ref) === -1 && dRefPtr !== refPtr && dRefPtr.indexOf(ref + '/') === 0) {
if (parentRefs.indexOf(ref) > -1) {
if (circulars.indexOf(ref) === -1) {
circulars.push(ref);
}
parentRefs.forEach(function (parentRef) {
if (circulars.indexOf(ref) === -1) {
circulars.push(parentRef);
}
});
} else {
walkRefs(parentPtrs.concat(refPtr), parentRefs.concat(ref), dRefPtr, dRefDetails.uri);
}

processedRefPtrs.push(refPtr);
processedRefs.push(ref);
}
});
}
Expand All @@ -350,7 +358,6 @@ function findRefsRecursive (obj, options, parents, parentPtrs, allRefs, indirect

if (circulars.indexOf(refDetails.uri) > -1) {
refDetails.circular = true;
refDetails.value = refDetails.def;
}
});
})
Expand Down

0 comments on commit 5ad1f63

Please sign in to comment.