@@ -13,9 +13,9 @@ pub use text_size::{TextRange, TextSize};
13
13
#[ derive( Clone , Debug , PartialEq , Eq ) ]
14
14
pub struct LineIndex {
15
15
/// Offset the beginning of each line, zero-based.
16
- newlines : Vec < TextSize > ,
16
+ newlines : Box < [ TextSize ] > ,
17
17
/// List of non-ASCII characters on each line.
18
- line_wide_chars : IntMap < u32 , Vec < WideChar > > ,
18
+ line_wide_chars : IntMap < u32 , Box < [ WideChar ] > > ,
19
19
}
20
20
21
21
/// Line/Column information in native, utf8 format.
@@ -97,7 +97,8 @@ impl LineIndex {
97
97
98
98
// Save any utf-16 characters seen in the previous line
99
99
if !wide_chars. is_empty ( ) {
100
- line_wide_chars. insert ( line, std:: mem:: take ( & mut wide_chars) ) ;
100
+ line_wide_chars
101
+ . insert ( line, std:: mem:: take ( & mut wide_chars) . into_boxed_slice ( ) ) ;
101
102
}
102
103
103
104
// Prepare for processing the next line
@@ -115,13 +116,10 @@ impl LineIndex {
115
116
116
117
// Save any utf-16 characters seen in the last line
117
118
if !wide_chars. is_empty ( ) {
118
- line_wide_chars. insert ( line, wide_chars) ;
119
+ line_wide_chars. insert ( line, wide_chars. into_boxed_slice ( ) ) ;
119
120
}
120
121
121
- newlines. shrink_to_fit ( ) ;
122
- line_wide_chars. shrink_to_fit ( ) ;
123
-
124
- LineIndex { newlines, line_wide_chars }
122
+ LineIndex { newlines : newlines. into_boxed_slice ( ) , line_wide_chars }
125
123
}
126
124
127
125
/// Transforms the `TextSize` into a `LineCol`.
@@ -168,7 +166,7 @@ impl LineIndex {
168
166
fn utf8_to_wide_col ( & self , enc : WideEncoding , line : u32 , col : TextSize ) -> usize {
169
167
let mut res: usize = col. into ( ) ;
170
168
if let Some ( wide_chars) = self . line_wide_chars . get ( & line) {
171
- for c in wide_chars {
169
+ for c in wide_chars. iter ( ) {
172
170
if c. end <= col {
173
171
res -= usize:: from ( c. len ( ) ) - c. wide_len ( enc) ;
174
172
} else {
@@ -183,7 +181,7 @@ impl LineIndex {
183
181
184
182
fn wide_to_utf8_col ( & self , enc : WideEncoding , line : u32 , mut col : u32 ) -> TextSize {
185
183
if let Some ( wide_chars) = self . line_wide_chars . get ( & line) {
186
- for c in wide_chars {
184
+ for c in wide_chars. iter ( ) {
187
185
if col > u32:: from ( c. start ) {
188
186
col += u32:: from ( c. len ( ) ) - c. wide_len ( enc) as u32 ;
189
187
} else {
0 commit comments