Skip to content

Commit

Permalink
Perf: refactor sanitiseRecursive
Browse files Browse the repository at this point in the history
As a side-effect, this introduces a limitation: the argument passed
to the initial `sanitiseRecursive` call must be an `Object` itself.
  • Loading branch information
jayaddison committed Nov 4, 2024
1 parent 1554551 commit 056c85b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions sphinx/themes/basic/static/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,12 @@ const Search = {

setIndex: (index) => {
const sanitiseRecursive = function(obj) {
if (obj instanceof Object && !Array.isArray(obj)) {
Object.entries(obj).map(([k, v]) => obj[k] = sanitiseRecursive(v));
return Object.freeze(Object.assign(Object.create(null), obj));
if (Array.isArray(obj)) return Object.freeze(obj);
const result = Object.create(null);
for (const [k, v] of Object.entries(obj)) {
result[k] = (v instanceof Object) ? sanitiseRecursive(v) : v;
}
return Object.freeze(obj);
return Object.freeze(result);
}
Search._index = sanitiseRecursive(index);
if (Search._queued_query !== null) {
Expand Down

0 comments on commit 056c85b

Please sign in to comment.