Skip to content

Commit e99bdd9

Browse files
committed
Swap jsvGetStringLength()>0 to jsvIsEmptyString(line) - a lot faster
1 parent 1263857 commit e99bdd9

File tree

10 files changed

+19
-19
lines changed

10 files changed

+19
-19
lines changed

libs/banglejs/jswrap_bangle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4016,7 +4016,7 @@ NO_INLINE void jswrap_banglejs_init() {
40164016
bool drawInfo = false;
40174017
JsVar *img = jsfReadFile(jsfNameFromString(".splash"),0,0);
40184018
int w,h;
4019-
if (!jsvIsString(img) || !jsvGetStringLength(img)) {
4019+
if (!jsvIsString(img) || jsvIsEmptyString(img)) {
40204020
jsvUnLock(img);
40214021
drawInfo = true;
40224022
img = jswrap_banglejs_getLogo();

libs/graphics/jswrap_graphics.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,7 @@ JsVar *jswrap_graphics_setFont(JsVar *parent, JsVar *fontId, int size) {
20122012
unsigned short sz = 0xFFFF; // the actual data mask
20132013
if (isVector) {
20142014
sz = (unsigned short)size;
2015-
} else if (jsvIsUndefined(name) || jsvGetStringLength(name)==0 || jsvIsStringEqual(name, "4x6"))
2015+
} else if (jsvIsUndefined(name) || jsvIsEmptyString(name) || jsvIsStringEqual(name, "4x6"))
20162016
sz = (unsigned short)(size + JSGRAPHICS_FONTSIZE_4X6);
20172017
#ifdef USE_FONT_6X8
20182018
if (jsvIsStringEqual(name, "6x8"))
@@ -2497,7 +2497,7 @@ JsVar *jswrap_graphics_wrapString(JsVar *parent, JsVar *str, int maxWidth) {
24972497
lineWidth += wordWidth;
24982498
} else { // doesn't fit on one line - put word on new line
24992499
lineWidth = wordWidth;
2500-
if (jsvGetStringLength(currentLine) || wasNewLine)
2500+
if (!jsvIsEmptyString(currentLine) || wasNewLine)
25012501
jsvArrayPush(lines, currentLine);
25022502
jsvUnLock(currentLine);
25032503
currentLine = 0;
@@ -2587,7 +2587,7 @@ JsVar *jswrap_graphics_wrapString(JsVar *parent, JsVar *str, int maxWidth) {
25872587
}
25882588
jsvStringIteratorFree(&it);
25892589
// deal with final line
2590-
if (jsvGetStringLength(currentLine)) {
2590+
if (!jsvIsEmptyString(currentLine)) {
25912591
jsvArrayPush(lines, currentLine);
25922592
}
25932593
jsvUnLock2(str,currentLine);
@@ -3903,7 +3903,7 @@ JsVar *jswrap_graphics_drawImages(JsVar *parent, JsVar *layersVar, JsVar *option
39033903
// compose operation
39043904
JsVar *opVar = jsvObjectGetChildIfExists(layer,"compose");
39053905
layers[i].compose = GFXDILC_REPLACE;
3906-
if (!opVar || !jsvGetStringLength(opVar)) layers[i].compose = GFXDILC_REPLACE;
3906+
if (!opVar || jsvIsEmptyString(opVar)) layers[i].compose = GFXDILC_REPLACE;
39073907
else if (jsvIsStringEqual(opVar,"add")) layers[i].compose = GFXDILC_ADD;
39083908
else if (jsvIsStringEqual(opVar,"or")) layers[i].compose = GFXDILC_OR;
39093909
else if (jsvIsStringEqual(opVar,"xor")) layers[i].compose = GFXDILC_XOR;

libs/network/esp8266/jswrap_esp8266_network.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ void jswrap_wifi_startAP(
568568
JsVar *jsPassword = jsvObjectGetChildIfExists(jsOptions, "password");
569569
if (jsPassword != NULL) {
570570
// handle password:null
571-
if (jsvGetStringLength(jsPassword) != 0) {
571+
if (!jsvIsEmptyString(jsPassword)) {
572572
if (!jsvIsString(jsPassword) || jsvGetStringLength(jsPassword) < 8) {
573573
jsExceptionHere(JSET_ERROR, "Password must be string of at least 8 characters");
574574
jsvUnLock(jsPassword);

libs/network/jswrap_net.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ JsVar *jswrap_url_parse(JsVar *url, bool parseQuery) {
143143
JsVar *v;
144144

145145
v = jsvNewWritableStringFromStringVar(url, (size_t)pathStart, JSVAPPENDSTRINGVAR_MAXLENGTH);
146-
if (jsvGetStringLength(v)==0) jsvAppendString(v, "/");
146+
if (jsvIsEmptyString(v)) jsvAppendString(v, "/");
147147
jsvObjectSetChildAndUnLock(obj, "path", v);
148148

149149
v = jsvNewWritableStringFromStringVar(url, (size_t)pathStart, (size_t)((searchStart>=0)?(searchStart-pathStart):JSVAPPENDSTRINGVAR_MAXLENGTH));
150-
if (jsvGetStringLength(v)==0) jsvAppendString(v, "/");
150+
if (jsvIsEmptyString(v)) jsvAppendString(v, "/");
151151
jsvObjectSetChildAndUnLock(obj, "pathname", v);
152152

153153
jsvObjectSetChildAndUnLock(obj, "search", (searchStart>=0)?jsvNewFromStringVar(url, (size_t)searchStart, JSVAPPENDSTRINGVAR_MAXLENGTH):jsvNewNull());
@@ -167,7 +167,7 @@ JsVar *jswrap_url_parse(JsVar *url, bool parseQuery) {
167167
while (jsvStringIteratorHasChar(&it)) {
168168
char ch = jsvStringIteratorGetCharAndNext(&it);
169169
if (ch=='&') {
170-
if (jsvGetStringLength(key)>0 || jsvGetStringLength(val)>0) {
170+
if (!jsvIsEmptyString(key) || !jsvIsEmptyString(val)) {
171171
key = jsvAsArrayIndexAndUnLock(key); // make sure "0" gets made into 0
172172
key = jsvMakeIntoVariableName(key, val);
173173
jsvAddName(query, key);
@@ -194,7 +194,7 @@ JsVar *jswrap_url_parse(JsVar *url, bool parseQuery) {
194194
jsvStringIteratorFree(&it);
195195
jsvUnLock(queryStr);
196196

197-
if (jsvGetStringLength(key)>0 || jsvGetStringLength(val)>0) {
197+
if (!jsvIsEmptyString(key) || !jsvIsEmptyString(val)) {
198198
key = jsvAsArrayIndexAndUnLock(key); // make sure "0" gets made into 0
199199
key = jsvMakeIntoVariableName(key, val);
200200
jsvAddName(query, key);

libs/network/socketserver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ bool socketClientConnectionsIdle(JsNetwork *net) {
696696
jsvObjectSetChildAndUnLock(connection, HTTP_NAME_CONNECTED, jsvNewFromBool(true));
697697
alreadyConnected = true;
698698
// if we do not have any data to send, issue a drain event
699-
if (!sendData || (int)jsvGetStringLength(sendData) == 0)
699+
if (!sendData || jsvIsEmptyString(sendData))
700700
jsiQueueObjectCallbacks(connection, HTTP_NAME_ON_DRAIN, &connection, 1);
701701
}
702702
// got data add it to our receive buffer
@@ -721,7 +721,7 @@ bool socketClientConnectionsIdle(JsNetwork *net) {
721721
if (!receiveData || jsvIsEmptyString(receiveData)) {
722722
// If we had data to send but the socket closed, this is an error
723723
JsVar *sendData = jsvObjectGetChildIfExists(connection,HTTP_NAME_SEND_DATA);
724-
if (sendData && jsvGetStringLength(sendData) > 0 && error == SOCKET_ERR_CLOSED)
724+
if (sendData && !jsvIsEmptyString(sendData) && error == SOCKET_ERR_CLOSED)
725725
error = SOCKET_ERR_UNSENT_DATA;
726726
jsvUnLock(sendData);
727727

libs/pixljs/jswrap_pixljs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ void jswrap_pixljs_init() {
426426
(jshPinGetValue(BTN4_PININDEX) == BTN4_ONSTATE)))
427427
splashScreen = jsfReadFile(jsfNameFromString(".splash"),0,0);
428428
if (jsvIsString(splashScreen)) {
429-
if (jsvGetStringLength(splashScreen)) {
429+
if (!jsvIsEmptyString(splashScreen)) {
430430
graphicsSetVar(&gfx);
431431
jsvUnLock(jswrap_graphics_drawImage(graphics, splashScreen,0,0,0));
432432
graphicsGetFromVar(&gfx, graphics);

src/jsinteractive.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,7 +1860,7 @@ static void jsiHandleConsoleChar(char ch) {
18601860
execInfo.execute &= ~EXEC_CTRL_C_MASK; // if we got Ctrl-C, ignore it
18611861

18621862
if (inputState == IPS_PACKET_TRANSFER_BYTE0) {
1863-
if (jsvGetStringLength(inputLine)==0)
1863+
if (jsvIsEmptyString(inputLine))
18641864
jsiStatus &= ~JSIS_ECHO_OFF_FOR_LINE; // turn on echo (because it'd have been turned off by DLE on an empty line)
18651865
inputPacketLength = ((uint8_t)ch) << 8;
18661866
inputState = IPS_PACKET_TRANSFER_BYTE1;
@@ -1882,13 +1882,13 @@ static void jsiHandleConsoleChar(char ch) {
18821882
} else if (ch == 3) { // Ctrl-c
18831883
// Ctrl-C (char code 3) gets handled in an IRQ but we just ignore it here
18841884
} else if (ch == 5) { // Ctrl-e
1885-
if (jsvGetStringLength(inputLine)==0)
1885+
if (jsvIsEmptyString(inputLine))
18861886
jsiConsolePrintf("Espruino %s %s\n",JS_VERSION,PC_BOARD_ID); // 5=ENQ - if sent on empty line and Espruino new enough, we transmit what we are
18871887
} else if (ch==16) {
18881888
/* DLE - Data Link Escape
18891889
Espruino uses DLE on the start of a line to signal that just the line in
18901890
question should be executed without echo */
1891-
if (jsvGetStringLength(inputLine)==0)
1891+
if (jsvIsEmptyString(inputLine))
18921892
jsiStatus |= JSIS_ECHO_OFF_FOR_LINE;
18931893
inputState = IPS_HAD_DLE;
18941894
} else if (ch == 27) {

src/jsvar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2245,7 +2245,7 @@ void jsvSetInteger(JsVar *v, JsVarInt value) {
22452245
*/
22462246
bool jsvGetBool(const JsVar *v) {
22472247
if (jsvIsString(v))
2248-
return jsvGetStringLength((JsVar*)v)!=0;
2248+
return !jsvIsEmptyString((JsVar*)v);
22492249
#ifndef ESPR_EMBED
22502250
if (jsvIsPin(v))
22512251
return jshIsPinValid(jshGetPinFromVar((JsVar*)v));

src/jswrap_modules.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ JsVar *jswrap_require(JsVar *moduleName) {
133133
jsvUnLock2(fileContents, exception);
134134
fileContents = 0;
135135
}
136-
if (fileContents && jsvGetStringLength(fileContents)>0)
136+
if (fileContents && !jsvIsEmptyString(fileContents))
137137
moduleExport = jspEvaluateModule(fileContents);
138138
jsvUnLock(fileContents);
139139
}

targets/esp8266/jswrap_esp8266.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Prints the contents of the debug log to the console.
149149
*/
150150
void jswrap_ESP8266_printLog() {
151151
JsVar *line = esp8266_logGetLine();
152-
while (jsvGetStringLength(line) > 0) {
152+
while (!jsvIsEmptyString(line)) {
153153
jsiConsolePrintStringVar(line);
154154
jsvUnLock(line);
155155
line = esp8266_logGetLine();

0 commit comments

Comments
 (0)