Conversation
resolve(scopes) { | ||
let granted = dfa.sortScopesForMerge(_.clone(scopes)); | ||
let granted = dfa.sortScopesForMerge(ScopeResolver.normalizeScopes(scopes)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is hot code... if we want to do this at the very least leave a //TODO: Avoid using ScopeResolver.normalizeScopes and normalize scopes using sorted result
Basically, ScopeResolver.normalizeScopes
is O(n^2) but after the sort by dfa.sortScopesForMerge
normalization is trivially done in O(n), see:
Lines 152 to 166 in 3c3b0c9
// At this stage i = n or j = m, meaning that one of our two lists is now | |
// empty, so we just add everything from one of them. But to ensure | |
// normalization, we still do the endsWith('*') trick, skipping scopes that | |
// are already satisfied. | |
while (i < n) { | |
let scope = scopes1[i]; | |
scopes.push(scope); | |
i += 1; | |
if (scope.endsWith('*')) { | |
let prefix = scope.slice(0, -1); | |
while(i < n && scopes1[i].startsWith(prefix)) { | |
i += 1; | |
} | |
} | |
} |
Technically, this could be done with mergeScopeSets(dfa.sortScopesForMerge(_.clone(scopes)), [])
which probably isn't even that bad an idea...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm saying this because we have spent time making sure this code path was fast.. :)
|
a54cc27
to
2e86c5c
Compare
Updated -- thanks! |
Got another one for you, @jonasfj