From 354c0a47016030024b1ab81ff0b914f3e800c0c5 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Wed, 20 Dec 2017 22:59:45 +0300 Subject: [PATCH] numbers parsing optimisation --- src/code.c | 47 +++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/src/code.c b/src/code.c index 9ce9122..c49dd93 100644 --- a/src/code.c +++ b/src/code.c @@ -430,6 +430,7 @@ static void parse(const char* start, u8* color) ptr = end ? end + strlen(BlockCommentEnd) : blockCommentStart + strlen(blockCommentStart); memset(color + (blockCommentStart - start), getConfig()->theme.code.comment, ptr - blockCommentStart); blockCommentStart = NULL; + continue; } else if(blockStringStart) { @@ -460,6 +461,7 @@ static void parse(const char* start, u8* color) memset(color + (blockStringStart - start), getConfig()->theme.code.string, ptr - blockStringStart); blockStringStart = NULL; + continue; } else if(singleCommentStart) { @@ -467,52 +469,33 @@ static void parse(const char* start, u8* color) memset(color + (singleCommentStart - start), getConfig()->theme.code.comment, ptr - singleCommentStart); singleCommentStart = NULL; + continue; } else if(numberStart) { - bool digit = true; while(!islineend(*ptr)) { char c = *ptr; - if(isdigit(c)) + if(isdigit(c)) ptr++; + else if(numberStart[0] == '0' + && (numberStart[1] == 'x' || numberStart[1] == 'X') + && isxdigit(numberStart[2])) { - ptr++; - } - else if(numberStart[0] == '0' && (numberStart[1] == 'x' || numberStart[1] == 'X')) - { - if(ptr - numberStart <= 2) - { - ptr++; - } - else if(ptr - numberStart > 2 && isxdigit(c)) - { - ptr++; - } - else - { - digit = false; - break; - } - } - else if(c == '.' || c == 'e') - { - if(isdigit(ptr[1])) - ptr++; + if((ptr - numberStart < 2) || (ptr - numberStart >= 2 && isxdigit(c))) ptr++; else break; } - else if(isalpha(c) || c == '_') + else if(c == '.' || c == 'e' || c == 'E') { - digit = false; - break; + if(isdigit(ptr[1])) ptr++; + else break; } else break; } - if(digit) - memset(color + (numberStart - start), getConfig()->theme.code.number, ptr - numberStart); - + memset(color + (numberStart - start), getConfig()->theme.code.number, ptr - numberStart); numberStart = NULL; + continue; } else { @@ -549,6 +532,10 @@ static void parse(const char* start, u8* color) ptr += 1; continue; } + else + { + // other stuff + } } } }