commit dc26586ceae77a5b41fd07d571b051543d97ce14
parent 45a0fb59cd00eaf54295dc9dcea5116de03291c4
Author: William Casarin <jb55@jb55.com>
Date: Sat, 11 Aug 2018 14:14:52 -0700
json: JSMN_PARENT_LINKS makes the parser a billion times faster
Diffstat:
5 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,7 +1,7 @@
BIN = lnvis
PREFIX ?= /usr/local
-CFLAGS = -Ideps -ggdb -O2 -Wall -Wextra -Werror -std=c99
+CFLAGS = -Ideps -ggdb -O2 -Wall -Wextra -Werror -std=c99 -DJSMN_PARENT_LINKS
LDFLAGS = -lglfw -lGL
diff --git a/defs.h b/defs.h
@@ -4,6 +4,8 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#include <inttypes.h>
+
typedef unsigned char u8;
typedef signed char s8;
@@ -13,8 +15,8 @@ typedef signed short s16;
typedef unsigned int u32;
typedef signed int s32;
-typedef unsigned long long u64;
-typedef signed long long s64;
+typedef uint64_t u64;
+typedef int64_t s64;
#endif /* LNVIS_DEFS_H */
diff --git a/json.c b/json.c
@@ -167,7 +167,7 @@ int parse_clightning_channels(FILE *fd, int *nchannels, struct channel **pchanne
if (tok->type == JSMN_ARRAY)
continue;
-
+
if (tok->type == JSMN_OBJECT) {
if (++objs > 2)
nchans++;
@@ -210,7 +210,7 @@ int parse_clightning_channels(FILE *fd, int *nchannels, struct channel **pchanne
break;
case PARSING_FLAGS:
- chan->satoshis = parse_u32(toklen, tokstr);
+ chan->flags = parse_u32(toklen, tokstr);
state = PARSING_TOKEN;
break;
@@ -249,7 +249,7 @@ int parse_clightning_channels(FILE *fd, int *nchannels, struct channel **pchanne
}
break;
}
-
+
}
*pchannels = channels;
diff --git a/ln.h b/ln.h
@@ -81,12 +81,12 @@ struct channel {
u16 flags;
- u64 satoshis;
-
u32 last_update_timestamp;
u32 delay;
u32 base_fee_msat;
u32 fee_per_millionth;
+
+ u64 satoshis;
};
enum display_flags {
diff --git a/main.c b/main.c
@@ -103,7 +103,7 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
static void print_channel(struct channel *chan)
{
- printf("chan shortid=%u:%u:%hu public=%d sats=%llu active=%d "
+ printf("chan shortid=%u:%u:%hu public=%d sats=%"PRIu64" active=%d "
"last_update=%u base_fee_msat=%u fee_per_millionth=%u "
"delay=%u\n",
chan->short_channel_id.blocknum,