this small change improves the interpreter running up to 11x faster when parsing each line of 3bc code.
How to do it
file in question to be modified: src/interpreter_syntax.c
it might be useful to look at the typedefs in src/3bc_types.h
it is necessary to sort the array keywords_opcode according to the first string of the struct.
replace linear search with binary search in interpreter_syntax_registers function.
using key.compare to compare string is longer or shorter as if it were a 4byte integer is ideal.
it's interesting to use a variable to not do double checks, just subtract once and then get the result if less, greater or equal.
use the equation keywords_opcode[i].keyword.compare - key.compare, to know if the result is to the left (if negative), or to the right (if positive), when zero, the value is correct.
this small change improves the interpreter running up to 11x faster when parsing each line of 3bc code.
How to do it
src/interpreter_syntax.c
src/3bc_types.h
keywords_opcode
according to the first string of the struct.interpreter_syntax_registers
function.key.compare
to compare string is longer or shorter as if it were a 4byte integer is ideal.keywords_opcode[i].keyword.compare - key.compare
, to know if the result is to the left (if negative), or to the right (if positive), when zero, the value is correct.