Optimize type comparisons #435
Labels
E-Easy
Easy
enhancement
New feature or request
good first issue
Good for newcomers
performance
Performance related changes and issues
Milestone
Current situation
Currently, if the interpreter wants to know what type a value is, it has to call
get_type()
, which returns a&str
, and compare it to another&str
. This takes a pretty log time.It would be much faster to just compare values in an enumeration, which should be at most 1-word size, and can therefore be stored in the stack easily.
We sill need the
&str
version of the type, though, since for example, thetypeof
operator needs to display it. I think the best option would be for theType
enum to implement a function calledas_str()
so that we can get the&str
value if needed.So, the idea is to have a
Type
enum, that is returned by theget_type()
function here, and then, that enum to have anas_str()
function with a similar code to the current function.The text was updated successfully, but these errors were encountered: