Skip to content

Commit

Permalink
Optimise pretokenised Strings so we load very short strings direct to…
Browse files Browse the repository at this point in the history
… RAM
  • Loading branch information
gfwilliams committed Jan 29, 2024
1 parent eee759e commit 2fa86d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Remove 65535-char max native string length restriction introduced in 2v20 on devices that could support more like Bangle.js 2
E.memoryArea(0, ...) now returns `undefined`
Fix issue using Flat/Flash/Native Strings to create fields in objects
Optimise pretokenised Strings so we load very short strings direct to RAM

2v20 : Ensure String.charCodeAt returns NaN for out of bounds chars
Bangle.js2: When rendering overlays, *do not* use the current FG/BG color for 1 bit overlays
Expand Down
23 changes: 16 additions & 7 deletions src/jslex.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,13 +592,22 @@ static void jslGetRawString() {
length |= ((unsigned char)lex->currCh)<<8;
}
jsvUnLock(lex->tokenValue);
size_t stringPos = jsvStringIteratorGetIndex(&lex->it);
lex->tokenValue = jsvNewFromStringVar(lex->sourceVar, stringPos, length);
// skip over string
// Why does lex->sourceVar get unlocked in this case???
jsvLockAgain(lex->it.var); // jsvStringIteratorGoto assumes var was locked
jsvStringIteratorGoto(&lex->it, lex->sourceVar, stringPos+length);
jsvUnLock(lex->it.var); // jsvStringIteratorGoto assumes var was locked
if (length > JSVAR_DATA_STRING_LEN) {
/* if it won't fit in a single string var, keep it in flash */
size_t stringPos = jsvStringIteratorGetIndex(&lex->it);
lex->tokenValue = jsvNewFromStringVar(lex->sourceVar, stringPos, length);
// skip over string
jsvLockAgain(lex->it.var); // jsvStringIteratorGoto assumes var was locked
jsvStringIteratorGoto(&lex->it, lex->sourceVar, stringPos+length);
jsvUnLock(lex->it.var); // jsvStringIteratorGoto assumes var was locked
} else {
/* if it will fit in a single string, allocate one and fill it up! */
lex->tokenValue = jsvNewWithFlags(JSV_STRING_0 + length);
for (int i=0;i<length;i++) {
jslGetNextCh();
lex->tokenValue->varData.str[i] = lex->currCh;
}
}
jslGetNextCh(); // ensure we're all set up with next char (might be able to optimise slightly, but this is safe)
}

Expand Down

0 comments on commit 2fa86d7

Please sign in to comment.