Changeset: Sort attributes by keys, not full string rep

pull/5268/head
Richard Hansen 2021-10-11 21:11:28 -04:00
parent 1cad5d881a
commit 9401ae876b
1 changed files with 11 additions and 3 deletions

View File

@ -1089,6 +1089,15 @@ exports.mutateTextLines = (cs, lines) => {
mut.close();
};
/**
* Sorts an array of attributes by key.
*
* @param {Attribute[]} attribs - The array of attributes to sort in place.
* @returns {Attribute[]} The `attribs` array.
*/
const sortAttribs =
(attribs) => attribs.sort((a, b) => (a[0] > b[0] ? 1 : 0) - (a[0] < b[0] ? 1 : 0));
/**
* Composes two attribute strings (see below) into one.
*
@ -1144,9 +1153,8 @@ exports.composeAttributes = (att1, att2, resultIsMutation, pool) => {
}
return '';
});
atts.sort();
const buf = exports.stringAssembler();
for (const att of atts) {
for (const att of sortAttribs(atts)) {
buf.append('*');
buf.append(exports.numToString(pool.putAttrib(att)));
}
@ -1900,7 +1908,7 @@ exports.makeAttribsString = (opcode, attribs, pool) => {
} else if (pool && attribs.length) {
if (attribs.length > 1) {
attribs = attribs.slice();
attribs.sort();
sortAttribs(attribs);
}
const result = [];
for (const pair of attribs) {