@@ -234,7 +234,7 @@ where
234
234
take ( & mut self . errors )
235
235
}
236
236
237
- fn set_last_start_tag_name ( & mut self , tag_name : & str ) {
237
+ fn set_last_start_tag_name ( & mut self , tag_name : & JsWord ) {
238
238
self . last_start_tag_name = Some ( tag_name. into ( ) ) ;
239
239
}
240
240
@@ -596,16 +596,11 @@ where
596
596
}
597
597
}
598
598
599
- fn start_new_attribute ( & mut self , c : Option < char > ) {
599
+ fn start_new_attribute ( & mut self ) {
600
600
if let Some ( Tag { attributes, .. } ) = & mut self . current_tag_token {
601
601
// The longest known attribute is "glyph-orientation-horizontal" for SVG tags
602
- let mut name = String :: with_capacity ( 28 ) ;
603
- let mut raw_name = String :: with_capacity ( 28 ) ;
604
-
605
- if let Some ( c) = c {
606
- name. push ( c) ;
607
- raw_name. push ( c) ;
608
- } ;
602
+ let name = String :: with_capacity ( 28 ) ;
603
+ let raw_name = String :: with_capacity ( 28 ) ;
609
604
610
605
attributes. push ( Attribute {
611
606
span : Default :: default ( ) ,
@@ -619,49 +614,49 @@ where
619
614
}
620
615
}
621
616
622
- fn append_to_attribute (
623
- & mut self ,
624
- name : Option < ( char , char ) > ,
625
- value : Option < ( bool , Option < char > , Option < char > ) > ,
626
- ) {
617
+ fn append_name_to_attribute ( & mut self , c : char , raw_c : Option < char > ) {
627
618
if let Some ( Tag { attributes, .. } ) = & mut self . current_tag_token {
628
619
if let Some ( attribute) = attributes. last_mut ( ) {
629
- if let Some ( name) = name {
630
- attribute. name . push ( name. 0 ) ;
620
+ attribute. name . push ( c) ;
631
621
622
+ if let Some ( raw_c) = raw_c {
632
623
if let Some ( raw_name) = & mut attribute. raw_name {
633
- raw_name. push ( name . 1 ) ;
624
+ raw_name. push ( raw_c ) ;
634
625
}
635
626
}
627
+ }
628
+ }
629
+ }
636
630
637
- if let Some ( value) = value {
638
- if let Some ( c) = value. 1 {
639
- if let Some ( old_value) = & mut attribute. value {
640
- old_value. push ( c) ;
641
- } else {
642
- let mut new_value = String :: with_capacity ( 255 ) ;
631
+ fn append_value_to_attribute ( & mut self , quotes : bool , c : Option < char > , raw_c : Option < char > ) {
632
+ if let Some ( Tag { attributes, .. } ) = & mut self . current_tag_token {
633
+ if let Some ( attribute) = attributes. last_mut ( ) {
634
+ if let Some ( c) = c {
635
+ if let Some ( old_value) = & mut attribute. value {
636
+ old_value. push ( c) ;
637
+ } else {
638
+ let mut new_value = String :: with_capacity ( 255 ) ;
643
639
644
- new_value. push ( c) ;
640
+ new_value. push ( c) ;
645
641
646
- attribute. value = Some ( new_value) ;
647
- }
642
+ attribute. value = Some ( new_value) ;
648
643
}
644
+ }
649
645
650
- if let Some ( c ) = value . 2 {
651
- // Quote for attribute was found, so we set empty value by default
652
- if value . 0 && attribute. value . is_none ( ) {
653
- attribute. value = Some ( String :: with_capacity ( 255 ) ) ;
654
- }
646
+ if let Some ( raw_c ) = raw_c {
647
+ // Quote for attribute was found, so we set empty value by default
648
+ if quotes && attribute. value . is_none ( ) {
649
+ attribute. value = Some ( String :: with_capacity ( 255 ) ) ;
650
+ }
655
651
656
- if let Some ( raw_value) = & mut attribute. raw_value {
657
- raw_value. push ( c ) ;
658
- } else {
659
- let mut raw_new_value = String :: with_capacity ( 255 ) ;
652
+ if let Some ( raw_value) = & mut attribute. raw_value {
653
+ raw_value. push ( raw_c ) ;
654
+ } else {
655
+ let mut raw_new_value = String :: with_capacity ( 255 ) ;
660
656
661
- raw_new_value. push ( c ) ;
657
+ raw_new_value. push ( raw_c ) ;
662
658
663
- attribute. raw_value = Some ( raw_new_value) ;
664
- }
659
+ attribute. raw_value = Some ( raw_new_value) ;
665
660
}
666
661
}
667
662
}
@@ -2178,23 +2173,24 @@ where
2178
2173
// We set `None` for `value` to support boolean attributes in AST
2179
2174
Some ( c @ '=' ) => {
2180
2175
self . emit_error ( ErrorKind :: UnexpectedEqualsSignBeforeAttributeName ) ;
2181
- self . start_new_attribute ( Some ( c) ) ;
2176
+ self . start_new_attribute ( ) ;
2177
+ self . append_name_to_attribute ( c, Some ( c) ) ;
2182
2178
self . state = State :: AttributeName ;
2183
2179
}
2184
2180
// Anything else
2185
2181
// Start a new attribute in the current tag token. Set that attribute name
2186
2182
// and value to the empty string. Reconsume in the attribute name state.
2187
2183
// We set `None` for `value` to support boolean attributes in AST
2188
2184
_ => {
2189
- self . start_new_attribute ( None ) ;
2185
+ self . start_new_attribute ( ) ;
2190
2186
self . reconsume_in_state ( State :: AttributeName ) ;
2191
2187
}
2192
2188
}
2193
2189
}
2194
2190
// https://html.spec.whatwg.org/multipage/parsing.html#attribute-name-state
2195
2191
State :: AttributeName => {
2196
2192
let anything_else = |lexer : & mut Lexer < I > , c : char | {
2197
- lexer. append_to_attribute ( Some ( ( c, c ) ) , None ) ;
2193
+ lexer. append_name_to_attribute ( c, Some ( c ) ) ;
2198
2194
} ;
2199
2195
2200
2196
// Consume the next input character:
@@ -2225,14 +2221,14 @@ where
2225
2221
// Append the lowercase version of the current input character (add 0x0020
2226
2222
// to the character's code point) to the current attribute's name.
2227
2223
Some ( c) if is_ascii_upper_alpha ( c) => {
2228
- self . append_to_attribute ( Some ( ( c. to_ascii_lowercase ( ) , c ) ) , None ) ;
2224
+ self . append_name_to_attribute ( c. to_ascii_lowercase ( ) , Some ( c ) ) ;
2229
2225
}
2230
2226
// U+0000 NULL
2231
2227
// This is an unexpected-null-character parse error. Append a U+FFFD
2232
2228
// REPLACEMENT CHARACTER character to the current attribute's name.
2233
2229
Some ( c @ '\x00' ) => {
2234
2230
self . emit_error ( ErrorKind :: UnexpectedNullCharacter ) ;
2235
- self . append_to_attribute ( Some ( ( REPLACEMENT_CHARACTER , c ) ) , None ) ;
2231
+ self . append_name_to_attribute ( REPLACEMENT_CHARACTER , Some ( c ) ) ;
2236
2232
}
2237
2233
// U+0022 QUOTATION MARK (")
2238
2234
// U+0027 APOSTROPHE (')
@@ -2304,7 +2300,7 @@ where
2304
2300
// and value to the empty string. Reconsume in the attribute name state.
2305
2301
// We set `None` for `value` to support boolean attributes in AST
2306
2302
_ => {
2307
- self . start_new_attribute ( None ) ;
2303
+ self . start_new_attribute ( ) ;
2308
2304
self . reconsume_in_state ( State :: AttributeName ) ;
2309
2305
}
2310
2306
}
@@ -2324,13 +2320,13 @@ where
2324
2320
// U+0022 QUOTATION MARK (")
2325
2321
// Switch to the attribute value (double-quoted) state.
2326
2322
Some ( c @ '"' ) => {
2327
- self . append_to_attribute ( None , Some ( ( true , None , Some ( c) ) ) ) ;
2323
+ self . append_value_to_attribute ( true , None , Some ( c) ) ;
2328
2324
self . state = State :: AttributeValueDoubleQuoted ;
2329
2325
}
2330
2326
// U+0027 APOSTROPHE (')
2331
2327
// Switch to the attribute value (single-quoted) state.
2332
2328
Some ( c @ '\'' ) => {
2333
- self . append_to_attribute ( None , Some ( ( true , None , Some ( c) ) ) ) ;
2329
+ self . append_value_to_attribute ( true , None , Some ( c) ) ;
2334
2330
self . state = State :: AttributeValueSingleQuoted ;
2335
2331
}
2336
2332
// U+003E GREATER-THAN SIGN (>)
@@ -2356,7 +2352,7 @@ where
2356
2352
// Switch to the after attribute value (quoted) state.
2357
2353
// We set value to support empty attributes (i.e. `attr=""`)
2358
2354
Some ( c @ '"' ) => {
2359
- self . append_to_attribute ( None , Some ( ( false , None , Some ( c) ) ) ) ;
2355
+ self . append_value_to_attribute ( false , None , Some ( c) ) ;
2360
2356
self . state = State :: AfterAttributeValueQuoted ;
2361
2357
}
2362
2358
// U+0026 AMPERSAND (&)
@@ -2371,10 +2367,7 @@ where
2371
2367
// REPLACEMENT CHARACTER character to the current attribute's value.
2372
2368
Some ( c @ '\x00' ) => {
2373
2369
self . emit_error ( ErrorKind :: UnexpectedNullCharacter ) ;
2374
- self . append_to_attribute (
2375
- None ,
2376
- Some ( ( false , Some ( REPLACEMENT_CHARACTER ) , Some ( c) ) ) ,
2377
- ) ;
2370
+ self . append_value_to_attribute ( false , Some ( REPLACEMENT_CHARACTER ) , Some ( c) ) ;
2378
2371
}
2379
2372
// EOF
2380
2373
// This is an eof-in-tag parse error. Emit an end-of-file token.
@@ -2388,7 +2381,7 @@ where
2388
2381
// Append the current input character to the current attribute's value.
2389
2382
Some ( c) => {
2390
2383
self . validate_input_stream_character ( c) ;
2391
- self . append_to_attribute ( None , Some ( ( false , Some ( c) , Some ( c) ) ) ) ;
2384
+ self . append_value_to_attribute ( false , Some ( c) , Some ( c) ) ;
2392
2385
}
2393
2386
}
2394
2387
}
@@ -2400,7 +2393,7 @@ where
2400
2393
// Switch to the after attribute value (quoted) state.
2401
2394
// We set value to support empty attributes (i.e. `attr=''`)
2402
2395
Some ( c @ '\'' ) => {
2403
- self . append_to_attribute ( None , Some ( ( false , None , Some ( c) ) ) ) ;
2396
+ self . append_value_to_attribute ( false , None , Some ( c) ) ;
2404
2397
self . state = State :: AfterAttributeValueQuoted ;
2405
2398
}
2406
2399
// U+0026 AMPERSAND (&)
@@ -2415,10 +2408,7 @@ where
2415
2408
// REPLACEMENT CHARACTER character to the current attribute's value.
2416
2409
Some ( c @ '\x00' ) => {
2417
2410
self . emit_error ( ErrorKind :: UnexpectedNullCharacter ) ;
2418
- self . append_to_attribute (
2419
- None ,
2420
- Some ( ( false , Some ( REPLACEMENT_CHARACTER ) , Some ( c) ) ) ,
2421
- ) ;
2411
+ self . append_value_to_attribute ( false , Some ( REPLACEMENT_CHARACTER ) , Some ( c) ) ;
2422
2412
}
2423
2413
// EOF
2424
2414
// This is an eof-in-tag parse error. Emit an end-of-file token.
@@ -2432,14 +2422,14 @@ where
2432
2422
// Append the current input character to the current attribute's value.
2433
2423
Some ( c) => {
2434
2424
self . validate_input_stream_character ( c) ;
2435
- self . append_to_attribute ( None , Some ( ( false , Some ( c) , Some ( c) ) ) ) ;
2425
+ self . append_value_to_attribute ( false , Some ( c) , Some ( c) ) ;
2436
2426
}
2437
2427
}
2438
2428
}
2439
2429
// https://html.spec.whatwg.org/multipage/parsing.html#attribute-value-(unquoted)-state
2440
2430
State :: AttributeValueUnquoted => {
2441
2431
let anything_else = |lexer : & mut Lexer < I > , c : char | {
2442
- lexer. append_to_attribute ( None , Some ( ( false , Some ( c) , Some ( c) ) ) ) ;
2432
+ lexer. append_value_to_attribute ( false , Some ( c) , Some ( c) ) ;
2443
2433
} ;
2444
2434
2445
2435
// Consume the next input character:
@@ -2473,10 +2463,7 @@ where
2473
2463
// REPLACEMENT CHARACTER character to the current attribute's value.
2474
2464
Some ( c @ '\x00' ) => {
2475
2465
self . emit_error ( ErrorKind :: UnexpectedNullCharacter ) ;
2476
- self . append_to_attribute (
2477
- None ,
2478
- Some ( ( false , Some ( REPLACEMENT_CHARACTER ) , Some ( c) ) ) ,
2479
- ) ;
2466
+ self . append_value_to_attribute ( false , Some ( REPLACEMENT_CHARACTER ) , Some ( c) ) ;
2480
2467
}
2481
2468
// U+0022 QUOTATION MARK (")
2482
2469
// U+0027 APOSTROPHE (')
@@ -4196,7 +4183,7 @@ where
4196
4183
// Otherwise, emit the current input character as a character token.
4197
4184
Some ( c) if c. is_ascii_alphanumeric ( ) => {
4198
4185
if self . is_consumed_as_part_of_an_attribute ( ) {
4199
- self . append_to_attribute ( None , Some ( ( false , Some ( c) , Some ( c) ) ) ) ;
4186
+ self . append_value_to_attribute ( false , Some ( c) , Some ( c) ) ;
4200
4187
} else {
4201
4188
self . emit_character_token ( c) ?;
4202
4189
}
1 commit comments
github-actions[bot] commentedon Oct 27, 2022
Benchmark
es/full/bugs-1
425656
ns/iter (± 12124
)351098
ns/iter (± 13736
)1.21
es/full/minify/libraries/antd
2112013799
ns/iter (± 23917214
)1902755724
ns/iter (± 30591665
)1.11
es/full/minify/libraries/d3
436986000
ns/iter (± 8385848
)412876150
ns/iter (± 16936844
)1.06
es/full/minify/libraries/echarts
1800964043
ns/iter (± 18143263
)1665869386
ns/iter (± 165102758
)1.08
es/full/minify/libraries/jquery
119725938
ns/iter (± 3836487
)97019617
ns/iter (± 6327132
)1.23
es/full/minify/libraries/lodash
140705740
ns/iter (± 2894877
)142928270
ns/iter (± 28017963
)0.98
es/full/minify/libraries/moment
70106299
ns/iter (± 460609
)61512055
ns/iter (± 2424335
)1.14
es/full/minify/libraries/react
24144169
ns/iter (± 281704
)20458342
ns/iter (± 699566
)1.18
es/full/minify/libraries/terser
330787959
ns/iter (± 13183300
)349326588
ns/iter (± 16923562
)0.95
es/full/minify/libraries/three
604775193
ns/iter (± 11840143
)592443534
ns/iter (± 19889612
)1.02
es/full/minify/libraries/typescript
4009473205
ns/iter (± 30798593
)3640111607
ns/iter (± 775570662
)1.10
es/full/minify/libraries/victory
904122343
ns/iter (± 20983518
)818085181
ns/iter (± 21394040
)1.11
es/full/minify/libraries/vue
178210396
ns/iter (± 4913465
)150694166
ns/iter (± 16114547
)1.18
es/full/codegen/es3
40808
ns/iter (± 486
)32709
ns/iter (± 694
)1.25
es/full/codegen/es5
40599
ns/iter (± 540
)32685
ns/iter (± 551
)1.24
es/full/codegen/es2015
40717
ns/iter (± 990
)32861
ns/iter (± 1124
)1.24
es/full/codegen/es2016
40545
ns/iter (± 712
)32689
ns/iter (± 932
)1.24
es/full/codegen/es2017
40537
ns/iter (± 846
)32759
ns/iter (± 1962
)1.24
es/full/codegen/es2018
40572
ns/iter (± 1096
)32785
ns/iter (± 4431
)1.24
es/full/codegen/es2019
40580
ns/iter (± 1502
)32721
ns/iter (± 595
)1.24
es/full/codegen/es2020
40719
ns/iter (± 864
)33265
ns/iter (± 548
)1.22
es/full/all/es3
232201716
ns/iter (± 4903607
)192896187
ns/iter (± 7174584
)1.20
es/full/all/es5
219331415
ns/iter (± 3412543
)182716767
ns/iter (± 7374127
)1.20
es/full/all/es2015
177321052
ns/iter (± 4010221
)145588591
ns/iter (± 7520312
)1.22
es/full/all/es2016
177739154
ns/iter (± 3677578
)144217344
ns/iter (± 6207969
)1.23
es/full/all/es2017
177918666
ns/iter (± 4961369
)144833095
ns/iter (± 10954996
)1.23
es/full/all/es2018
175457004
ns/iter (± 4340355
)142447115
ns/iter (± 4386895
)1.23
es/full/all/es2019
176206418
ns/iter (± 4462392
)141718989
ns/iter (± 4894981
)1.24
es/full/all/es2020
166514582
ns/iter (± 4176959
)136371626
ns/iter (± 4117309
)1.22
es/full/parser
882187
ns/iter (± 48365
)723572
ns/iter (± 34702
)1.22
es/full/base/fixer
32344
ns/iter (± 3300
)25784
ns/iter (± 398
)1.25
es/full/base/resolver_and_hygiene
114658
ns/iter (± 4395
)91475
ns/iter (± 3030
)1.25
serialization of ast node
259
ns/iter (± 3
)216
ns/iter (± 4
)1.20
serialization of serde
263
ns/iter (± 22
)217
ns/iter (± 5
)1.21
This comment was automatically generated by workflow using github-action-benchmark.