Skip to content
Snippets Groups Projects
Commit da813689 authored by deuce's avatar deuce
Browse files

Add a flatten() command which takes a string as an argument.

This is to deal with the fact that when you concatenate JS strings, the JS
engine simply notes that they are concatenated, but keeps all the original
strings around until something flattens them.  This code:

for(;;) {
	str += ascii(random(256));
	log(str.length);
}

Fails when str reaches about 256KiB then crashes with out of memory but
this code:

for(;;) {
	str += ascii(random(256));
	log(str.length);
}

Reaches a size of 4MB without stopping.

Any time you actually paw through the string, it gets flattened, but when
you do a bunch of concatenation, manually flattening can be a Good Thing.
parent ce8e3c63
Branches
Tags
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment