Skip to content

Commit b9ea86d

Browse files
committed
Simple string concatenation is very slow for large amounts of data.
Using stringbuilder vastly improves performance.
1 parent d227ad7 commit b9ea86d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Diff for: src/LZString.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public static string decompress(string compressed)
232232
int enlargeIn = 4;
233233
int numBits = 3;
234234
string entry = "";
235-
string result = "";
235+
StringBuilder result = new StringBuilder();
236236
int i = 0;
237237
dynamic w = "";
238238
dynamic c = "";
@@ -265,7 +265,8 @@ public static string decompress(string compressed)
265265
}
266266

267267
dictionary.Add(c);
268-
w = result = c;
268+
result.Append(c);
269+
w = result.ToString();
269270

270271
while (true)
271272
{
@@ -292,7 +293,7 @@ public static string decompress(string compressed)
292293

293294
break;
294295
case 2:
295-
return result;
296+
return result.ToString();
296297
}
297298

298299
if (enlargeIn == 0)
@@ -318,7 +319,7 @@ public static string decompress(string compressed)
318319
}
319320
}
320321

321-
result += entry;
322+
result.Append(entry);
322323
dictionary.Add(w + entry[0]);
323324
enlargeIn--;
324325
w = entry;

0 commit comments

Comments
 (0)