mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
Swap jsvGetStringLength()>0 to jsvIsEmptyString(line) - a lot faster
This commit is contained in:
parent
1263857ebd
commit
e99bdd9541
@ -4016,7 +4016,7 @@ NO_INLINE void jswrap_banglejs_init() {
|
|||||||
bool drawInfo = false;
|
bool drawInfo = false;
|
||||||
JsVar *img = jsfReadFile(jsfNameFromString(".splash"),0,0);
|
JsVar *img = jsfReadFile(jsfNameFromString(".splash"),0,0);
|
||||||
int w,h;
|
int w,h;
|
||||||
if (!jsvIsString(img) || !jsvGetStringLength(img)) {
|
if (!jsvIsString(img) || jsvIsEmptyString(img)) {
|
||||||
jsvUnLock(img);
|
jsvUnLock(img);
|
||||||
drawInfo = true;
|
drawInfo = true;
|
||||||
img = jswrap_banglejs_getLogo();
|
img = jswrap_banglejs_getLogo();
|
||||||
|
|||||||
@ -2012,7 +2012,7 @@ JsVar *jswrap_graphics_setFont(JsVar *parent, JsVar *fontId, int size) {
|
|||||||
unsigned short sz = 0xFFFF; // the actual data mask
|
unsigned short sz = 0xFFFF; // the actual data mask
|
||||||
if (isVector) {
|
if (isVector) {
|
||||||
sz = (unsigned short)size;
|
sz = (unsigned short)size;
|
||||||
} else if (jsvIsUndefined(name) || jsvGetStringLength(name)==0 || jsvIsStringEqual(name, "4x6"))
|
} else if (jsvIsUndefined(name) || jsvIsEmptyString(name) || jsvIsStringEqual(name, "4x6"))
|
||||||
sz = (unsigned short)(size + JSGRAPHICS_FONTSIZE_4X6);
|
sz = (unsigned short)(size + JSGRAPHICS_FONTSIZE_4X6);
|
||||||
#ifdef USE_FONT_6X8
|
#ifdef USE_FONT_6X8
|
||||||
if (jsvIsStringEqual(name, "6x8"))
|
if (jsvIsStringEqual(name, "6x8"))
|
||||||
@ -2497,7 +2497,7 @@ JsVar *jswrap_graphics_wrapString(JsVar *parent, JsVar *str, int maxWidth) {
|
|||||||
lineWidth += wordWidth;
|
lineWidth += wordWidth;
|
||||||
} else { // doesn't fit on one line - put word on new line
|
} else { // doesn't fit on one line - put word on new line
|
||||||
lineWidth = wordWidth;
|
lineWidth = wordWidth;
|
||||||
if (jsvGetStringLength(currentLine) || wasNewLine)
|
if (!jsvIsEmptyString(currentLine) || wasNewLine)
|
||||||
jsvArrayPush(lines, currentLine);
|
jsvArrayPush(lines, currentLine);
|
||||||
jsvUnLock(currentLine);
|
jsvUnLock(currentLine);
|
||||||
currentLine = 0;
|
currentLine = 0;
|
||||||
@ -2587,7 +2587,7 @@ JsVar *jswrap_graphics_wrapString(JsVar *parent, JsVar *str, int maxWidth) {
|
|||||||
}
|
}
|
||||||
jsvStringIteratorFree(&it);
|
jsvStringIteratorFree(&it);
|
||||||
// deal with final line
|
// deal with final line
|
||||||
if (jsvGetStringLength(currentLine)) {
|
if (!jsvIsEmptyString(currentLine)) {
|
||||||
jsvArrayPush(lines, currentLine);
|
jsvArrayPush(lines, currentLine);
|
||||||
}
|
}
|
||||||
jsvUnLock2(str,currentLine);
|
jsvUnLock2(str,currentLine);
|
||||||
@ -3903,7 +3903,7 @@ JsVar *jswrap_graphics_drawImages(JsVar *parent, JsVar *layersVar, JsVar *option
|
|||||||
// compose operation
|
// compose operation
|
||||||
JsVar *opVar = jsvObjectGetChildIfExists(layer,"compose");
|
JsVar *opVar = jsvObjectGetChildIfExists(layer,"compose");
|
||||||
layers[i].compose = GFXDILC_REPLACE;
|
layers[i].compose = GFXDILC_REPLACE;
|
||||||
if (!opVar || !jsvGetStringLength(opVar)) layers[i].compose = GFXDILC_REPLACE;
|
if (!opVar || jsvIsEmptyString(opVar)) layers[i].compose = GFXDILC_REPLACE;
|
||||||
else if (jsvIsStringEqual(opVar,"add")) layers[i].compose = GFXDILC_ADD;
|
else if (jsvIsStringEqual(opVar,"add")) layers[i].compose = GFXDILC_ADD;
|
||||||
else if (jsvIsStringEqual(opVar,"or")) layers[i].compose = GFXDILC_OR;
|
else if (jsvIsStringEqual(opVar,"or")) layers[i].compose = GFXDILC_OR;
|
||||||
else if (jsvIsStringEqual(opVar,"xor")) layers[i].compose = GFXDILC_XOR;
|
else if (jsvIsStringEqual(opVar,"xor")) layers[i].compose = GFXDILC_XOR;
|
||||||
|
|||||||
@ -568,7 +568,7 @@ void jswrap_wifi_startAP(
|
|||||||
JsVar *jsPassword = jsvObjectGetChildIfExists(jsOptions, "password");
|
JsVar *jsPassword = jsvObjectGetChildIfExists(jsOptions, "password");
|
||||||
if (jsPassword != NULL) {
|
if (jsPassword != NULL) {
|
||||||
// handle password:null
|
// handle password:null
|
||||||
if (jsvGetStringLength(jsPassword) != 0) {
|
if (!jsvIsEmptyString(jsPassword)) {
|
||||||
if (!jsvIsString(jsPassword) || jsvGetStringLength(jsPassword) < 8) {
|
if (!jsvIsString(jsPassword) || jsvGetStringLength(jsPassword) < 8) {
|
||||||
jsExceptionHere(JSET_ERROR, "Password must be string of at least 8 characters");
|
jsExceptionHere(JSET_ERROR, "Password must be string of at least 8 characters");
|
||||||
jsvUnLock(jsPassword);
|
jsvUnLock(jsPassword);
|
||||||
|
|||||||
@ -143,11 +143,11 @@ JsVar *jswrap_url_parse(JsVar *url, bool parseQuery) {
|
|||||||
JsVar *v;
|
JsVar *v;
|
||||||
|
|
||||||
v = jsvNewWritableStringFromStringVar(url, (size_t)pathStart, JSVAPPENDSTRINGVAR_MAXLENGTH);
|
v = jsvNewWritableStringFromStringVar(url, (size_t)pathStart, JSVAPPENDSTRINGVAR_MAXLENGTH);
|
||||||
if (jsvGetStringLength(v)==0) jsvAppendString(v, "/");
|
if (jsvIsEmptyString(v)) jsvAppendString(v, "/");
|
||||||
jsvObjectSetChildAndUnLock(obj, "path", v);
|
jsvObjectSetChildAndUnLock(obj, "path", v);
|
||||||
|
|
||||||
v = jsvNewWritableStringFromStringVar(url, (size_t)pathStart, (size_t)((searchStart>=0)?(searchStart-pathStart):JSVAPPENDSTRINGVAR_MAXLENGTH));
|
v = jsvNewWritableStringFromStringVar(url, (size_t)pathStart, (size_t)((searchStart>=0)?(searchStart-pathStart):JSVAPPENDSTRINGVAR_MAXLENGTH));
|
||||||
if (jsvGetStringLength(v)==0) jsvAppendString(v, "/");
|
if (jsvIsEmptyString(v)) jsvAppendString(v, "/");
|
||||||
jsvObjectSetChildAndUnLock(obj, "pathname", v);
|
jsvObjectSetChildAndUnLock(obj, "pathname", v);
|
||||||
|
|
||||||
jsvObjectSetChildAndUnLock(obj, "search", (searchStart>=0)?jsvNewFromStringVar(url, (size_t)searchStart, JSVAPPENDSTRINGVAR_MAXLENGTH):jsvNewNull());
|
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) {
|
|||||||
while (jsvStringIteratorHasChar(&it)) {
|
while (jsvStringIteratorHasChar(&it)) {
|
||||||
char ch = jsvStringIteratorGetCharAndNext(&it);
|
char ch = jsvStringIteratorGetCharAndNext(&it);
|
||||||
if (ch=='&') {
|
if (ch=='&') {
|
||||||
if (jsvGetStringLength(key)>0 || jsvGetStringLength(val)>0) {
|
if (!jsvIsEmptyString(key) || !jsvIsEmptyString(val)) {
|
||||||
key = jsvAsArrayIndexAndUnLock(key); // make sure "0" gets made into 0
|
key = jsvAsArrayIndexAndUnLock(key); // make sure "0" gets made into 0
|
||||||
key = jsvMakeIntoVariableName(key, val);
|
key = jsvMakeIntoVariableName(key, val);
|
||||||
jsvAddName(query, key);
|
jsvAddName(query, key);
|
||||||
@ -194,7 +194,7 @@ JsVar *jswrap_url_parse(JsVar *url, bool parseQuery) {
|
|||||||
jsvStringIteratorFree(&it);
|
jsvStringIteratorFree(&it);
|
||||||
jsvUnLock(queryStr);
|
jsvUnLock(queryStr);
|
||||||
|
|
||||||
if (jsvGetStringLength(key)>0 || jsvGetStringLength(val)>0) {
|
if (!jsvIsEmptyString(key) || !jsvIsEmptyString(val)) {
|
||||||
key = jsvAsArrayIndexAndUnLock(key); // make sure "0" gets made into 0
|
key = jsvAsArrayIndexAndUnLock(key); // make sure "0" gets made into 0
|
||||||
key = jsvMakeIntoVariableName(key, val);
|
key = jsvMakeIntoVariableName(key, val);
|
||||||
jsvAddName(query, key);
|
jsvAddName(query, key);
|
||||||
|
|||||||
@ -696,7 +696,7 @@ bool socketClientConnectionsIdle(JsNetwork *net) {
|
|||||||
jsvObjectSetChildAndUnLock(connection, HTTP_NAME_CONNECTED, jsvNewFromBool(true));
|
jsvObjectSetChildAndUnLock(connection, HTTP_NAME_CONNECTED, jsvNewFromBool(true));
|
||||||
alreadyConnected = true;
|
alreadyConnected = true;
|
||||||
// if we do not have any data to send, issue a drain event
|
// if we do not have any data to send, issue a drain event
|
||||||
if (!sendData || (int)jsvGetStringLength(sendData) == 0)
|
if (!sendData || jsvIsEmptyString(sendData))
|
||||||
jsiQueueObjectCallbacks(connection, HTTP_NAME_ON_DRAIN, &connection, 1);
|
jsiQueueObjectCallbacks(connection, HTTP_NAME_ON_DRAIN, &connection, 1);
|
||||||
}
|
}
|
||||||
// got data add it to our receive buffer
|
// got data add it to our receive buffer
|
||||||
@ -721,7 +721,7 @@ bool socketClientConnectionsIdle(JsNetwork *net) {
|
|||||||
if (!receiveData || jsvIsEmptyString(receiveData)) {
|
if (!receiveData || jsvIsEmptyString(receiveData)) {
|
||||||
// If we had data to send but the socket closed, this is an error
|
// If we had data to send but the socket closed, this is an error
|
||||||
JsVar *sendData = jsvObjectGetChildIfExists(connection,HTTP_NAME_SEND_DATA);
|
JsVar *sendData = jsvObjectGetChildIfExists(connection,HTTP_NAME_SEND_DATA);
|
||||||
if (sendData && jsvGetStringLength(sendData) > 0 && error == SOCKET_ERR_CLOSED)
|
if (sendData && !jsvIsEmptyString(sendData) && error == SOCKET_ERR_CLOSED)
|
||||||
error = SOCKET_ERR_UNSENT_DATA;
|
error = SOCKET_ERR_UNSENT_DATA;
|
||||||
jsvUnLock(sendData);
|
jsvUnLock(sendData);
|
||||||
|
|
||||||
|
|||||||
@ -426,7 +426,7 @@ void jswrap_pixljs_init() {
|
|||||||
(jshPinGetValue(BTN4_PININDEX) == BTN4_ONSTATE)))
|
(jshPinGetValue(BTN4_PININDEX) == BTN4_ONSTATE)))
|
||||||
splashScreen = jsfReadFile(jsfNameFromString(".splash"),0,0);
|
splashScreen = jsfReadFile(jsfNameFromString(".splash"),0,0);
|
||||||
if (jsvIsString(splashScreen)) {
|
if (jsvIsString(splashScreen)) {
|
||||||
if (jsvGetStringLength(splashScreen)) {
|
if (!jsvIsEmptyString(splashScreen)) {
|
||||||
graphicsSetVar(&gfx);
|
graphicsSetVar(&gfx);
|
||||||
jsvUnLock(jswrap_graphics_drawImage(graphics, splashScreen,0,0,0));
|
jsvUnLock(jswrap_graphics_drawImage(graphics, splashScreen,0,0,0));
|
||||||
graphicsGetFromVar(&gfx, graphics);
|
graphicsGetFromVar(&gfx, graphics);
|
||||||
|
|||||||
@ -1860,7 +1860,7 @@ static void jsiHandleConsoleChar(char ch) {
|
|||||||
execInfo.execute &= ~EXEC_CTRL_C_MASK; // if we got Ctrl-C, ignore it
|
execInfo.execute &= ~EXEC_CTRL_C_MASK; // if we got Ctrl-C, ignore it
|
||||||
|
|
||||||
if (inputState == IPS_PACKET_TRANSFER_BYTE0) {
|
if (inputState == IPS_PACKET_TRANSFER_BYTE0) {
|
||||||
if (jsvGetStringLength(inputLine)==0)
|
if (jsvIsEmptyString(inputLine))
|
||||||
jsiStatus &= ~JSIS_ECHO_OFF_FOR_LINE; // turn on echo (because it'd have been turned off by DLE on an empty line)
|
jsiStatus &= ~JSIS_ECHO_OFF_FOR_LINE; // turn on echo (because it'd have been turned off by DLE on an empty line)
|
||||||
inputPacketLength = ((uint8_t)ch) << 8;
|
inputPacketLength = ((uint8_t)ch) << 8;
|
||||||
inputState = IPS_PACKET_TRANSFER_BYTE1;
|
inputState = IPS_PACKET_TRANSFER_BYTE1;
|
||||||
@ -1882,13 +1882,13 @@ static void jsiHandleConsoleChar(char ch) {
|
|||||||
} else if (ch == 3) { // Ctrl-c
|
} else if (ch == 3) { // Ctrl-c
|
||||||
// Ctrl-C (char code 3) gets handled in an IRQ but we just ignore it here
|
// Ctrl-C (char code 3) gets handled in an IRQ but we just ignore it here
|
||||||
} else if (ch == 5) { // Ctrl-e
|
} else if (ch == 5) { // Ctrl-e
|
||||||
if (jsvGetStringLength(inputLine)==0)
|
if (jsvIsEmptyString(inputLine))
|
||||||
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
|
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
|
||||||
} else if (ch==16) {
|
} else if (ch==16) {
|
||||||
/* DLE - Data Link Escape
|
/* DLE - Data Link Escape
|
||||||
Espruino uses DLE on the start of a line to signal that just the line in
|
Espruino uses DLE on the start of a line to signal that just the line in
|
||||||
question should be executed without echo */
|
question should be executed without echo */
|
||||||
if (jsvGetStringLength(inputLine)==0)
|
if (jsvIsEmptyString(inputLine))
|
||||||
jsiStatus |= JSIS_ECHO_OFF_FOR_LINE;
|
jsiStatus |= JSIS_ECHO_OFF_FOR_LINE;
|
||||||
inputState = IPS_HAD_DLE;
|
inputState = IPS_HAD_DLE;
|
||||||
} else if (ch == 27) {
|
} else if (ch == 27) {
|
||||||
|
|||||||
@ -2245,7 +2245,7 @@ void jsvSetInteger(JsVar *v, JsVarInt value) {
|
|||||||
*/
|
*/
|
||||||
bool jsvGetBool(const JsVar *v) {
|
bool jsvGetBool(const JsVar *v) {
|
||||||
if (jsvIsString(v))
|
if (jsvIsString(v))
|
||||||
return jsvGetStringLength((JsVar*)v)!=0;
|
return !jsvIsEmptyString((JsVar*)v);
|
||||||
#ifndef ESPR_EMBED
|
#ifndef ESPR_EMBED
|
||||||
if (jsvIsPin(v))
|
if (jsvIsPin(v))
|
||||||
return jshIsPinValid(jshGetPinFromVar((JsVar*)v));
|
return jshIsPinValid(jshGetPinFromVar((JsVar*)v));
|
||||||
|
|||||||
@ -133,7 +133,7 @@ JsVar *jswrap_require(JsVar *moduleName) {
|
|||||||
jsvUnLock2(fileContents, exception);
|
jsvUnLock2(fileContents, exception);
|
||||||
fileContents = 0;
|
fileContents = 0;
|
||||||
}
|
}
|
||||||
if (fileContents && jsvGetStringLength(fileContents)>0)
|
if (fileContents && !jsvIsEmptyString(fileContents))
|
||||||
moduleExport = jspEvaluateModule(fileContents);
|
moduleExport = jspEvaluateModule(fileContents);
|
||||||
jsvUnLock(fileContents);
|
jsvUnLock(fileContents);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -149,7 +149,7 @@ Prints the contents of the debug log to the console.
|
|||||||
*/
|
*/
|
||||||
void jswrap_ESP8266_printLog() {
|
void jswrap_ESP8266_printLog() {
|
||||||
JsVar *line = esp8266_logGetLine();
|
JsVar *line = esp8266_logGetLine();
|
||||||
while (jsvGetStringLength(line) > 0) {
|
while (!jsvIsEmptyString(line)) {
|
||||||
jsiConsolePrintStringVar(line);
|
jsiConsolePrintStringVar(line);
|
||||||
jsvUnLock(line);
|
jsvUnLock(line);
|
||||||
line = esp8266_logGetLine();
|
line = esp8266_logGetLine();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user