~pixelherodev/zyg

a371178a49439771172da003b474c1cd039d29d8 — Noam Preil 5 months ago 476c460
[lexer] minor optimization
1 files changed, 12 insertions(+), 12 deletions(-)

M lexer.c
M lexer.c => lexer.c +12 -12
@@ 331,13 331,13 @@ lex_string(void)
static void
lexer_append(void)
{
	// If you see "handle used but not set" or some such: LEAVE IT ALONE. Not initializing handle when its value isn't actually needed, since lexer_append is VERY HOT, has a noticable performance gain, and has no real downsides aside from the need to ensure that the whitelist of internalized tags is correct
	// If you see "handle used but not set" or some such: LEAVE IT ALONE. Not initializing handle when its value isn't actually needed, and since lexer_append is VERY HOT it has a noticable performance gain, and has no real downsides aside from the need to ensure that the whitelist of internalized tags is correct
	uint32_t handle;
//	if(ctx.token.tag != C3_WHILE && ctx.token.tag != C3_RBRACE && ctx.token.tag != C3_TRUE && ctx.token.tag != C3_LBRACE && ctx.token.tag != C3_LPAREN && ctx.token.tag != C3_RPAREN){
	if(ctx.token.tag == C3_IDENT || ctx.token.tag == C3_LITERAL_STRING || ctx.token.tag == C3_LINT){
		handle = c3intern(&ctx.tree, ctx.token.ptr, ctx.token.len);
		if(handle == -1)
			FATAL("Failed to intern string", 0);
			OOM();
	}
	if(!stb_sb_push_u32(&ctx.tokens.strings, handle) || !stb_sb_push_u8(&ctx.tokens.tags, ctx.token.tag))
		OOM();


@@ 371,21 371,15 @@ zyg_lex(char *path)
		c = ctx.file.buf[ctx.index];
		if(c == 0)
			break;
		if(c == '('){
		if(is_alpha(c) || c == '_' || c == '@'){
			lex_alpha();
		}else if(c == '('){
			ctx.token.tag = C3_LPAREN;
			ctx.index += 1;
		}else if(ARG("+=", 2)){
			ctx.index += 2;
			ctx.token.tag = C3_PLUS_EQUAL;
		}else if(ARG("-=", 2)){
			ctx.index += 2;
			ctx.token.tag = C3_MINUS_EQUAL;
		}else if(c == ')'){
			ctx.token.tag = C3_RPAREN;
			ctx.index += 1;
		}else if(is_alpha(c) || c == '_' || c == '@')
			lex_alpha();
		else if(c == '='){
		}else if(c == '='){
			ctx.token.tag = C3_EQ;
			ctx.index += 1;
		}else if(c == '{'){


@@ 433,6 427,12 @@ zyg_lex(char *path)
		}else if(c == '-'){
			ctx.token.tag = C3_MINUS;
			ctx.index += 1;
		}else if(ARG("+=", 2)){
			ctx.index += 2;
			ctx.token.tag = C3_PLUS_EQUAL;
		}else if(ARG("-=", 2)){
			ctx.index += 2;
			ctx.token.tag = C3_MINUS_EQUAL;
		}else if(c == '!'){
			ctx.token.tag = C3_EXCLAIM;
			ctx.index += 1;