ref: 69cb649c2ba55c0364c99f2adf20218feb4f53fc
parent: c87898e63b24d89de26f68e70df00a73cc64554d
author: Tor Andersson <tor@ccxvii.net>
date: Thu Mar 6 16:23:51 EST 2014
Use array helper functions.
--- a/jsfunction.c
+++ b/jsfunction.c
@@ -85,7 +85,6 @@
static void Fp_apply(js_State *J, unsigned int argc)
{
int i, n;
- char name[20];
if (!js_iscallable(J, 0))
js_typeerror(J, "not a function");
@@ -93,14 +92,9 @@
js_copy(J, 0);
js_copy(J, 1);
- js_getproperty(J, 2, "length");
- n = js_tonumber(J, -1);
- js_pop(J, 1);
-
- for (i = 0; i < n; ++i) {
- sprintf(name, "%d", i);
- js_getproperty(J, 2, name);
- }
+ n = js_getlength(J, 2);
+ for (i = 0; i < n; ++i)
+ js_getindex(J, 2, i);
js_call(J, n);
}
--- a/json.c
+++ b/json.c
@@ -171,15 +171,13 @@
static void fmtarray(js_State *J, js_Buffer **sb)
{
- unsigned int len, k;
+ unsigned int n, k;
char buf[40];
- js_getproperty(J, -1, "length");
- len = js_touint32(J, -1);
- js_pop(J, 1);
+ n = js_getlength(J, -1);
js_putc(J, sb, '[');
- for (k = 0; k < len; ++k) {
+ for (k = 0; k < n; ++k) {
if (k) js_putc(J, sb, ',');
sprintf(buf, "%u", k);
js_getproperty(J, -1, buf);