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