@@ -145,47 +145,15 @@ public static string EncodeString(byte[] buff, char[] charset) {
145145 for ( int i = 1 ; i < buff . Length ; i ++ ) {
146146 current = ( current << 8 ) + buff [ i ] ;
147147 while ( current >= charset . Length ) {
148- ret . Append ( charset [ current % charset . Length ] ) ;
149- current /= charset . Length ;
148+ current = Math . DivRem ( current , charset . Length , out int remainder ) ;
149+ ret . Append ( charset [ remainder ] ) ;
150150 }
151151 }
152152 if ( current != 0 )
153153 ret . Append ( charset [ current % charset . Length ] ) ;
154154 return ret . ToString ( ) ;
155155 }
156156
157- /// <summary>
158- /// Returns a new string in which all occurrences of a specified string in
159- /// <paramref name="str" /> are replaced with another specified string.
160- /// </summary>
161- /// <returns>
162- /// A <see cref="string" /> equivalent to <paramref name="str" /> but with all instances of
163- /// <paramref name="oldValue" />
164- /// replaced with <paramref name="newValue" />.
165- /// </returns>
166- /// <param name="str">A string to do the replace in. </param>
167- /// <param name="oldValue">A string to be replaced. </param>
168- /// <param name="newValue">A string to replace all occurrences of <paramref name="oldValue" />. </param>
169- /// <param name="comparison">One of the <see cref="StringComparison" /> values. </param>
170- /// <remarks>Adopted from http://stackoverflow.com/a/244933 </remarks>
171- public static string Replace ( this string str , string oldValue , string newValue , StringComparison comparison ) {
172- StringBuilder sb = new StringBuilder ( ) ;
173-
174- int previousIndex = 0 ;
175- int index = str . IndexOf ( oldValue , comparison ) ;
176- while ( index != - 1 ) {
177- sb . Append ( str . Substring ( previousIndex , index - previousIndex ) ) ;
178- sb . Append ( newValue ) ;
179- index += oldValue . Length ;
180- previousIndex = index ;
181- index = str . IndexOf ( oldValue , index , comparison ) ;
182- }
183- sb . Append ( str . Substring ( previousIndex ) ) ;
184-
185- return sb . ToString ( ) ;
186- }
187-
188-
189157 /// <summary>
190158 /// Encode the buffer to a hexadecimal string.
191159 /// </summary>
@@ -208,12 +176,17 @@ public static string ToHexString(byte[] buff) {
208176 /// <param name="self">The list to remove from.</param>
209177 /// <param name="match">The predicate that defines the conditions of the elements to remove.</param>
210178 /// <returns><paramref name="self" /> for method chaining.</returns>
211- public static IList < T > RemoveWhere < T > ( this IList < T > self , Predicate < T > match ) {
179+ public static void RemoveWhere < T > ( this IList < T > self , Predicate < T > match ) {
180+ if ( self is List < T > list ) {
181+ list . RemoveAll ( match ) ;
182+ return ;
183+ }
184+
185+ // Switch to slow algorithm
212186 for ( int i = self . Count - 1 ; i >= 0 ; i -- ) {
213187 if ( match ( self [ i ] ) )
214188 self . RemoveAt ( i ) ;
215189 }
216- return self ;
217190 }
218191
219192 /// <summary>
0 commit comments