File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,8 @@ impl SharedEncoding {
8080 #[ must_use]
8181 pub fn get ( & self ) -> & ' static Encoding {
8282 let encoding = self . encoding . load ( Ordering :: Relaxed ) ;
83- ALL_ENCODINGS [ encoding]
83+ // it will never be out of range, but get() avoids a panic branch
84+ ALL_ENCODINGS . get ( encoding) . unwrap_or ( & ALL_ENCODINGS [ 0 ] )
8485 }
8586
8687 pub fn set ( & self , encoding : AsciiCompatibleEncoding ) {
Original file line number Diff line number Diff line change @@ -67,7 +67,13 @@ impl TextDecoder {
6767 // the last call to feed_text() may make multiple calls to output_handler,
6868 // but only one call to output_handler can be *the* last one.
6969 let really_last = last_in_text_node && finished_decoding;
70- ( output_handler) ( & buffer[ ..written] , really_last, encoding) ?;
70+
71+ ( output_handler) (
72+ // this will always be in bounds, but unwrap_or_default optimizes better
73+ buffer. get ( ..written) . unwrap_or_default ( ) ,
74+ really_last,
75+ encoding,
76+ ) ?;
7177 }
7278
7379 if finished_decoding {
@@ -76,7 +82,7 @@ impl TextDecoder {
7682 }
7783 return Ok ( ( ) ) ;
7884 }
79- raw_input = & raw_input[ read..] ;
85+ raw_input = raw_input. get ( read..) . unwrap_or_default ( ) ;
8086 }
8187 }
8288
You can’t perform that action at this time.
0 commit comments