Skip to content

Commit

Permalink
Refactor: translate from sanitiseRecursive to an iterative approach
Browse files Browse the repository at this point in the history
  • Loading branch information
jayaddison committed Nov 5, 2024
1 parent e6ecded commit 6b4b675
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions sphinx/themes/basic/static/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,15 @@ const Search = {
(document.body.appendChild(document.createElement("script")).src = url),

setIndex: (index) => {
const evaluate = x => (x instanceof Object) ? sanitiseRecursive(x) : x;
const sanitiseRecursive = function(obj) {
Object.values(obj).map(evaluate);
if (!Array.isArray(obj)) Object.setPrototypeOf(obj, null);
return Object.freeze(obj);
const stack = [index];
while (stack.length) {
const value = stack.pop();
if (!(value instanceof Object)) continue;
stack.push(...Object.values(value));
if (!Array.isArray(value)) Object.setPrototypeOf(value, null);
Object.freeze(value);
}
Search._index = sanitiseRecursive(index);
Search._index = index;
if (Search._queued_query !== null) {
const query = Search._queued_query;
Search._queued_query = null;
Expand Down

0 comments on commit 6b4b675

Please sign in to comment.