--- node_modules/jsdoc/lib/jsdoc/util/templateHelper.js.orig +++ node_modules/jsdoc/lib/jsdoc/util/templateHelper.js @@ -804,7 +804,27 @@ return returnTypes; }; + +// Cache for memberof index to speed up ancestor lookups +let memberofIndex = null; + +function buildMemberofIndex(data) { + if (memberofIndex) { + return memberofIndex; + } + + memberofIndex = new Map(); + const allDoclets = data().get(); + + for (const doclet of allDoclets) { + if (doclet.longname) { + memberofIndex.set(doclet.longname, doclet); + } + } + return memberofIndex; +} + /** * Retrieve an ordered list of doclets for a symbol's ancestors. * @@ -818,9 +838,13 @@ let doc = doclet; let previousDoc; + // Build index once for all lookups + const index = buildMemberofIndex(data); + while (doc) { previousDoc = doc; - doc = find(data, {longname: doc.memberof})[0]; + // Use index instead of database query + doc = index.get(doc.memberof); // prevent infinite loop that can be caused by duplicated module definitions if (previousDoc === doc) {