@@ -1129,32 +1129,23 @@ exports.composeAttributes = (att1, att2, resultIsMutation, pool) => {
1129
1129
return att2 ;
1130
1130
}
1131
1131
if ( ! att2 ) return att1 ;
1132
- const atts = [ ] ;
1132
+ const atts = new Map ( ) ;
1133
1133
att1 . replace ( / \* ( [ 0 - 9 a - z ] + ) / g, ( _ , a ) => {
1134
- atts . push ( pool . getAttrib ( exports . parseNum ( a ) ) ) ;
1134
+ const [ key , val ] = pool . getAttrib ( exports . parseNum ( a ) ) ;
1135
+ atts . set ( key , val ) ;
1135
1136
return '' ;
1136
1137
} ) ;
1137
1138
att2 . replace ( / \* ( [ 0 - 9 a - z ] + ) / g, ( _ , a ) => {
1138
- const pair = pool . getAttrib ( exports . parseNum ( a ) ) ;
1139
- let found = false ;
1140
- for ( let i = 0 ; i < atts . length ; i ++ ) {
1141
- const oldPair = atts [ i ] ;
1142
- if ( oldPair [ 0 ] !== pair [ 0 ] ) continue ;
1143
- if ( pair [ 1 ] || resultIsMutation ) {
1144
- oldPair [ 1 ] = pair [ 1 ] ;
1145
- } else {
1146
- atts . splice ( i , 1 ) ;
1147
- }
1148
- found = true ;
1149
- break ;
1150
- }
1151
- if ( ( ! found ) && ( pair [ 1 ] || resultIsMutation ) ) {
1152
- atts . push ( pair ) ;
1139
+ const [ key , val ] = pool . getAttrib ( exports . parseNum ( a ) ) ;
1140
+ if ( val || resultIsMutation ) {
1141
+ atts . set ( key , val ) ;
1142
+ } else {
1143
+ atts . delete ( key ) ;
1153
1144
}
1154
1145
return '' ;
1155
1146
} ) ;
1156
1147
const buf = exports . stringAssembler ( ) ;
1157
- for ( const att of sortAttribs ( atts ) ) {
1148
+ for ( const att of sortAttribs ( [ ... atts ] ) ) {
1158
1149
buf . append ( '*' ) ;
1159
1150
buf . append ( exports . numToString ( pool . putAttrib ( att ) ) ) ;
1160
1151
}
@@ -2265,22 +2256,15 @@ const followAttributes = (att1, att2, pool) => {
2265
2256
// to produce the merged set.
2266
2257
if ( ( ! att2 ) || ( ! pool ) ) return '' ;
2267
2258
if ( ! att1 ) return att2 ;
2268
- const atts = [ ] ;
2259
+ const atts = new Map ( ) ;
2269
2260
att2 . replace ( / \* ( [ 0 - 9 a - z ] + ) / g, ( _ , a ) => {
2270
- atts . push ( pool . getAttrib ( exports . parseNum ( a ) ) ) ;
2261
+ const [ key , val ] = pool . getAttrib ( exports . parseNum ( a ) ) ;
2262
+ atts . set ( key , val ) ;
2271
2263
return '' ;
2272
2264
} ) ;
2273
2265
att1 . replace ( / \* ( [ 0 - 9 a - z ] + ) / g, ( _ , a ) => {
2274
- const pair1 = pool . getAttrib ( exports . parseNum ( a ) ) ;
2275
- for ( let i = 0 ; i < atts . length ; i ++ ) {
2276
- const pair2 = atts [ i ] ;
2277
- if ( pair1 [ 0 ] !== pair2 [ 0 ] ) continue ;
2278
- if ( pair1 [ 1 ] <= pair2 [ 1 ] ) {
2279
- // winner of merge is pair1, delete this attribute
2280
- atts . splice ( i , 1 ) ;
2281
- }
2282
- break ;
2283
- }
2266
+ const [ key , val ] = pool . getAttrib ( exports . parseNum ( a ) ) ;
2267
+ if ( atts . has ( key ) && val <= atts . get ( key ) ) atts . delete ( key ) ;
2284
2268
return '' ;
2285
2269
} ) ;
2286
2270
// we've only removed attributes, so they're already sorted
0 commit comments