@@ -108,7 +108,9 @@ public static int[] newLinePositions(string text, out int count) {
108
108
TextBuff _textBuf ;
109
109
float [ ] _charWidths ;
110
110
List < int > _breaks = new List < int > ( ) ;
111
+ int _breaksCount = 0 ;
111
112
List < float > _widths = new List < float > ( ) ;
113
+ int _widthsCount = 0 ;
112
114
WordBreaker _wordBreaker = new WordBreaker ( ) ;
113
115
float _width = 0.0f ;
114
116
float _preBreak ;
@@ -120,19 +122,28 @@ public static int[] newLinePositions(string text, out int count) {
120
122
TabStops _tabStops ;
121
123
int mFirstTabIndex ;
122
124
List < Candidate > _candidates = new List < Candidate > ( ) ;
125
+ int _candidatesCount = 0 ;
123
126
124
127
public int computeBreaks ( ) {
125
- int nCand = this . _candidates . Count ;
128
+ int nCand = this . _candidatesCount ;
126
129
if ( nCand > 0 && ( nCand == 1 || this . _lastBreak != nCand - 1 ) ) {
127
- var cand = this . _candidates . last ( ) ;
130
+ var cand = this . _candidates [ this . _candidatesCount - 1 ] ;
128
131
this . _pushBreak ( cand . offset , ( cand . postBreak - this . _preBreak ) ) ;
129
132
}
130
133
131
- return this . _breaks . Count ;
134
+ return this . _breaksCount ;
132
135
}
133
136
134
- public List < int > getBreaks ( ) {
135
- return this . _breaks ;
137
+ public int getBreaksCount ( ) {
138
+ return this . _breaksCount ;
139
+ }
140
+
141
+ public int getBreak ( int i ) {
142
+ return this . _breaks [ i ] ;
143
+ }
144
+
145
+ public float getWidth ( int i ) {
146
+ return this . _widths [ i ] ;
136
147
}
137
148
138
149
public void resize ( int size ) {
@@ -145,11 +156,11 @@ public void setText(string text, int textOffset, int textLength) {
145
156
this . _textBuf = new TextBuff ( text , textOffset , textLength ) ;
146
157
this . _wordBreaker . setText ( this . _textBuf ) ;
147
158
this . _wordBreaker . next ( ) ;
148
- this . _candidates . Clear ( ) ;
159
+ this . _candidatesCount = 0 ;
149
160
Candidate can = new Candidate {
150
161
offset = 0 , postBreak = 0 , preBreak = 0 , postSpaceCount = 0 , preSpaceCount = 0 , pre = 0
151
162
} ;
152
- this . _candidates . Add ( can ) ;
163
+ this . _addCandidateToList ( can ) ;
153
164
this . _lastBreak = 0 ;
154
165
this . _bestBreak = 0 ;
155
166
this . _bestScore = ScoreInfty ;
@@ -208,14 +219,14 @@ public void addStyleRun(TextStyle style, int start, int end) {
208
219
public void finish ( ) {
209
220
this . _wordBreaker . finish ( ) ;
210
221
this . _width = 0 ;
211
- this . _candidates . Clear ( ) ;
212
- this . _widths . Clear ( ) ;
213
- this . _breaks . Clear ( ) ;
222
+ this . _candidatesCount = 0 ;
223
+ this . _breaksCount = 0 ;
224
+ this . _widthsCount = 0 ;
214
225
this . _textBuf = default ;
215
226
}
216
227
217
- public List < float > getWidths ( ) {
218
- return this . _widths ;
228
+ public int getWidthsCount ( ) {
229
+ return this . _widthsCount ;
219
230
}
220
231
221
232
public void setTabStops ( TabStops tabStops ) {
@@ -225,7 +236,7 @@ public void setTabStops(TabStops tabStops) {
225
236
void _addWordBreak ( int offset , float preBreak , float postBreak , int preSpaceCount , int postSpaceCount ,
226
237
float penalty ) {
227
238
228
- float width = this . _candidates . last ( ) . preBreak ;
239
+ float width = this . _candidates [ this . _candidatesCount - 1 ] . preBreak ;
229
240
if ( postBreak - width > this . _lineWidth ) {
230
241
this . _addCandidatesInsideWord ( width , offset , postSpaceCount ) ;
231
242
}
@@ -241,7 +252,7 @@ void _addWordBreak(int offset, float preBreak, float postBreak, int preSpaceCoun
241
252
}
242
253
243
254
void _addCandidatesInsideWord ( float width , int offset , int postSpaceCount ) {
244
- int i = this . _candidates . last ( ) . offset ;
255
+ int i = this . _candidates [ this . _candidatesCount - 1 ] . offset ;
245
256
width += this . _charWidths [ i ++ ] ;
246
257
for ( ; i < offset ; i ++ ) {
247
258
float w = this . _charWidths [ i ] ;
@@ -259,10 +270,19 @@ void _addCandidatesInsideWord(float width, int offset, int postSpaceCount) {
259
270
}
260
271
}
261
272
273
+ void _addCandidateToList ( Candidate cand ) {
274
+ if ( this . _candidates . Count == this . _candidatesCount ) {
275
+ this . _candidates . Add ( cand ) ;
276
+ this . _candidatesCount ++ ;
277
+ }
278
+ else {
279
+ this . _candidates [ this . _candidatesCount ++ ] = cand ;
280
+ }
281
+ }
262
282
263
283
void _addCandidate ( Candidate cand ) {
264
- int candIndex = this . _candidates . Count ;
265
- this . _candidates . Add ( cand ) ;
284
+ int candIndex = this . _candidatesCount ;
285
+ this . _addCandidateToList ( cand ) ;
266
286
if ( cand . postBreak - this . _preBreak > this . _lineWidth ) {
267
287
if ( this . _bestBreak == this . _lastBreak ) {
268
288
this . _bestBreak = candIndex ;
@@ -299,9 +319,22 @@ void _pushGreedyBreak() {
299
319
}
300
320
301
321
void _pushBreak ( int offset , float width ) {
302
- if ( this . lineLimit == 0 || this . _breaks . Count < this . lineLimit ) {
303
- this . _breaks . Add ( offset ) ;
304
- this . _widths . Add ( width ) ;
322
+ if ( this . lineLimit == 0 || this . _breaksCount < this . lineLimit ) {
323
+ if ( this . _breaks . Count == this . _breaksCount ) {
324
+ this . _breaks . Add ( offset ) ;
325
+ this . _breaksCount ++ ;
326
+ }
327
+ else {
328
+ this . _breaks [ this . _breaksCount ++ ] = offset ;
329
+ }
330
+
331
+ if ( this . _widths . Count == this . _widthsCount ) {
332
+ this . _widths . Add ( width ) ;
333
+ this . _widthsCount ++ ;
334
+ }
335
+ else {
336
+ this . _widths [ this . _widthsCount ++ ] = width ;
337
+ }
305
338
}
306
339
}
307
340
}
0 commit comments