File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -110,6 +110,10 @@ impl PullParser {
110110 if let Some ( enc) = config. override_encoding {
111111 lexer. set_encoding ( enc) ;
112112 }
113+
114+ let mut pos = Vec :: with_capacity ( 16 ) ;
115+ pos. push ( TextPosition :: new ( ) ) ;
116+
113117 PullParser {
114118 config,
115119 lexer,
@@ -133,7 +137,7 @@ impl PullParser {
133137 final_result : None ,
134138 next_event : None ,
135139 est : Vec :: new ( ) ,
136- pos : vec ! [ TextPosition :: new ( ) ] ,
140+ pos,
137141
138142 encountered : Encountered :: None ,
139143 inside_whitespace : true ,
@@ -399,7 +403,12 @@ impl PullParser {
399403
400404 #[ inline]
401405 fn push_pos ( & mut self ) {
402- self . pos . push ( self . lexer . position ( ) ) ;
406+ debug_assert ! ( self . pos. len( ) != self . pos. capacity( ) , "How did you get a document that weird? Please file a bug" ) ;
407+
408+ // it has capacity preallocated for more than it ever needs, so this reduces code size
409+ if self . pos . len ( ) != self . pos . capacity ( ) {
410+ self . pos . push ( self . lexer . position ( ) ) ;
411+ }
403412 }
404413
405414 #[ inline( never) ]
Original file line number Diff line number Diff line change @@ -79,13 +79,16 @@ pub struct Emitter {
7979
8080impl Emitter {
8181 pub fn new ( config : EmitterConfig ) -> Emitter {
82+ let mut indent_stack = Vec :: with_capacity ( 16 ) ;
83+ indent_stack. push ( IndentFlags :: WroteNothing ) ;
84+
8285 Emitter {
8386 config,
8487
8588 nst : NamespaceStack :: empty ( ) ,
8689
8790 indent_level : 0 ,
88- indent_stack : vec ! [ IndentFlags :: WroteNothing ] ,
91+ indent_stack,
8992
9093 element_names : Vec :: new ( ) ,
9194
You can’t perform that action at this time.
0 commit comments