-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Move natural-sort functionality into packages/internal #10320
base: master
Are you sure you want to change the base?
Conversation
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.
Interesting, I didn't know we had this natural compare. I wish it was used in a few more places (vatID, etc.)
I'd like to come back to review this more closely.
/** | ||
* @param {string} a | ||
* @param {string} b | ||
* @returns {-1 | 0 | 1} | ||
*/ | ||
const compareNats = (a, b) => { |
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.
My understanding is that this logic works even is the params are number
, right?
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.
Mostly, but not when either is NaN or both are infinite. And this function is not exported, so we can count on the input arguments always being decimal digit strings.
Deploying agoric-sdk with Cloudflare Pages
|
Removes unnecessary use of localeCompare Ref endojs/endo#2113
3240449
to
9e6b7ad
Compare
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.
nice refactor, but that pre-existing weirdness in kernelKeeper.dumpState needs addressing
return 1; | ||
// Perform an element-by-element natural sort. | ||
kernelTable.sort((a, b) => { | ||
const len = Math.min(a.length, b.length); |
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 feels wrong.. actually the original feels wrong too. The kernelTable
data is mostly created by calling vatKeeper.dumpState()
, and that returns a 3-tuple of [kernelSlot, vatID, vatSlot]
. It would make the most sense to use naturalCompare
separately on each of the three components (krefs, vatIDs, and vrefs all have the same letters-then-digits shape).
I don't know why the original was treating the rows as six-tuples. My best guess is it thought a[0], a[1], a[2]
was individual characters of a kref, so the ko
prefix would be compared by strings, and the digit suffix would be compared by number. But that doesn't make a lot of sense either.
In any case, I think we want something more like:
kernelTable.sort((a,b) =>
naturalCompare(a[0], b[0]) ||
naturalCompare(a[1], b[1]) ||
naturalCompare(a[2], b[2]) || 0);
unless you can make more sense of the old code than me..
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.
Yeah, that makes sense. I just realized I typo'd the general form anyway (a[0]
and b[0]
rather than a[i]
and b[i]
).
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.
that looks good to me, but I'll defer to @mhofman if he's got something more specific to look at
Ref endojs/endo#2113
Description
Removes unnecessary use of
localeCompare
and consolidates natural-order sorting.Security Considerations
n/a
Scaling Considerations
n/a
Documentation Considerations
n/a
Testing Considerations
None in particular, although I probably should add something to packages/internal/test.
Upgrade Considerations
This code runs outside of all vats (and AFAIK is not exercised on-chain at all) and is safe to include in any release.