mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
[ecmascript] Avoid strlen
This commit is contained in:
parent
be40c1bb87
commit
c8aba2ef8c
@ -145,6 +145,7 @@ struct mjs_xhr {
|
|||||||
int method;
|
int method;
|
||||||
int status;
|
int status;
|
||||||
int timeout;
|
int timeout;
|
||||||
|
size_t responseLength;
|
||||||
unsigned short readyState;
|
unsigned short readyState;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -516,6 +517,7 @@ mjs_xhr_open(js_State *J)
|
|||||||
xhr->responseHeaders.clear();
|
xhr->responseHeaders.clear();
|
||||||
mem_free_set(&xhr->response, NULL);
|
mem_free_set(&xhr->response, NULL);
|
||||||
mem_free_set(&xhr->responseText, NULL);
|
mem_free_set(&xhr->responseText, NULL);
|
||||||
|
xhr->responseLength = 0;
|
||||||
|
|
||||||
if (xhr->readyState != OPENED) {
|
if (xhr->readyState != OPENED) {
|
||||||
xhr->readyState = OPENED;
|
xhr->readyState = OPENED;
|
||||||
@ -782,11 +784,7 @@ write_data(void *ptr, size_t size, size_t nmemb, void *stream)
|
|||||||
{
|
{
|
||||||
struct mjs_xhr *xhr = (mjs_xhr *)stream;
|
struct mjs_xhr *xhr = (mjs_xhr *)stream;
|
||||||
|
|
||||||
size_t length = 0;
|
size_t length = xhr->responseLength;
|
||||||
|
|
||||||
if (xhr->responseText) {
|
|
||||||
length = strlen(xhr->responseText);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *n = (char *)mem_realloc(xhr->responseText, length + size * nmemb + 1);
|
char *n = (char *)mem_realloc(xhr->responseText, length + size * nmemb + 1);
|
||||||
|
|
||||||
@ -797,6 +795,7 @@ write_data(void *ptr, size_t size, size_t nmemb, void *stream)
|
|||||||
}
|
}
|
||||||
memcpy(xhr->responseText + length, ptr, (size * nmemb));
|
memcpy(xhr->responseText + length, ptr, (size * nmemb));
|
||||||
xhr->responseText[length + size * nmemb] = '\0';
|
xhr->responseText[length + size * nmemb] = '\0';
|
||||||
|
xhr->responseLength += size * nmemb;
|
||||||
|
|
||||||
return nmemb;
|
return nmemb;
|
||||||
}
|
}
|
||||||
|
@ -230,6 +230,7 @@ typedef struct {
|
|||||||
int status;
|
int status;
|
||||||
char *status_text;
|
char *status_text;
|
||||||
char *response_text;
|
char *response_text;
|
||||||
|
size_t response_length;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
JSValue url;
|
JSValue url;
|
||||||
@ -1192,6 +1193,7 @@ xhr_open(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
|||||||
x->events[i] = JS_UNDEFINED;
|
x->events[i] = JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
mem_free_set(&x->response_text, NULL);
|
mem_free_set(&x->response_text, NULL);
|
||||||
|
x->response_length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x->ready_state < XHR_RSTATE_OPENED) {
|
if (x->ready_state < XHR_RSTATE_OPENED) {
|
||||||
@ -1317,12 +1319,7 @@ static size_t
|
|||||||
write_data(void *ptr, size_t size, size_t nmemb, void *stream)
|
write_data(void *ptr, size_t size, size_t nmemb, void *stream)
|
||||||
{
|
{
|
||||||
Xhr *x = (Xhr *)stream;
|
Xhr *x = (Xhr *)stream;
|
||||||
|
size_t length = x->response_length;
|
||||||
size_t length = 0;
|
|
||||||
|
|
||||||
if (x->response_text) {
|
|
||||||
length = strlen(x->response_text);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *n = (char *)mem_realloc(x->response_text, length + size * nmemb + 1);
|
char *n = (char *)mem_realloc(x->response_text, length + size * nmemb + 1);
|
||||||
|
|
||||||
@ -1333,6 +1330,7 @@ write_data(void *ptr, size_t size, size_t nmemb, void *stream)
|
|||||||
}
|
}
|
||||||
memcpy(x->response_text + length, ptr, (size * nmemb));
|
memcpy(x->response_text + length, ptr, (size * nmemb));
|
||||||
x->response_text[length + size * nmemb] = '\0';
|
x->response_text[length + size * nmemb] = '\0';
|
||||||
|
x->response_length += size * nmemb;
|
||||||
|
|
||||||
return nmemb;
|
return nmemb;
|
||||||
}
|
}
|
||||||
|
@ -153,6 +153,7 @@ struct xhr {
|
|||||||
int status;
|
int status;
|
||||||
int timeout;
|
int timeout;
|
||||||
unsigned short readyState;
|
unsigned short readyState;
|
||||||
|
size_t responseLength;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void onload_run(void *data);
|
static void onload_run(void *data);
|
||||||
@ -678,6 +679,7 @@ xhr_open(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
|||||||
xhr->responseHeaders.clear();
|
xhr->responseHeaders.clear();
|
||||||
mem_free_set(&xhr->response, NULL);
|
mem_free_set(&xhr->response, NULL);
|
||||||
mem_free_set(&xhr->responseText, NULL);
|
mem_free_set(&xhr->responseText, NULL);
|
||||||
|
xhr->responseLength = 0;
|
||||||
|
|
||||||
if (xhr->readyState != OPENED) {
|
if (xhr->readyState != OPENED) {
|
||||||
xhr->readyState = OPENED;
|
xhr->readyState = OPENED;
|
||||||
@ -934,12 +936,7 @@ static size_t
|
|||||||
write_data(void *ptr, size_t size, size_t nmemb, void *stream)
|
write_data(void *ptr, size_t size, size_t nmemb, void *stream)
|
||||||
{
|
{
|
||||||
struct xhr *xhr = (struct xhr *)stream;
|
struct xhr *xhr = (struct xhr *)stream;
|
||||||
|
size_t length = xhr->responseLength;
|
||||||
size_t length = 0;
|
|
||||||
|
|
||||||
if (xhr->responseText) {
|
|
||||||
length = strlen(xhr->responseText);
|
|
||||||
}
|
|
||||||
char *n = (char *)mem_realloc(xhr->responseText, length + size * nmemb + 1);
|
char *n = (char *)mem_realloc(xhr->responseText, length + size * nmemb + 1);
|
||||||
|
|
||||||
if (n) {
|
if (n) {
|
||||||
@ -949,6 +946,7 @@ write_data(void *ptr, size_t size, size_t nmemb, void *stream)
|
|||||||
}
|
}
|
||||||
memcpy(xhr->responseText + length, ptr, (size * nmemb));
|
memcpy(xhr->responseText + length, ptr, (size * nmemb));
|
||||||
xhr->responseText[length + size * nmemb] = '\0';
|
xhr->responseText[length + size * nmemb] = '\0';
|
||||||
|
xhr->responseLength += size * nmemb;
|
||||||
|
|
||||||
return nmemb;
|
return nmemb;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user