Operating system or device:
Windows 10
Issue description (what happened, and what was expected):
Typing "q0" in your script gets it highlighted in yellow even though it's not a keyword.
Steps to reproduce:
Type "q0" into a script and bask in the yellow light.
Can confirm
@bojidar-bg and I had a look and it doesn't seem obvious to find the cause of this bug, so removing the junior job tag.
Here is a snippet from IRC, showing our finds (not from official godot engine channels):
The problem is in String::hash() in ustring.cpp.
It seems the hash generated for "q0" is the same as for the keyword "or" :)
here's an improved algorithm for the hashing function (less collisions and better performance)
static const unsigned int FNV_PRIME = 16777619u;
static const unsigned int OFFSET_BASIS = 2166136261u;
unsigned int hash2(char* str)
{
unsigned int hash = OFFSET_BASIS;
while ((*str))
{
hash ^= *str++;
hash *=FNV_PRIME;
}
return hash;
}
PS - I tested and compared the performance of the two algs in a 10000000 for cycle. My suggested solution is faster, but only when the strings are relatively small. When I switched to longer strings (14chars), the performance was only slightly worse than the current one.
@nunodonato ~ BTW, your solution might (must) still have collisions. That's a general problem with hashing... Maybe a better solution would be to compare strings directly, even after the same-hash test passes :smile:
Still, if it is better, we might include your hash function too.
Feel free to make a PR with your hash function, if performance is about the
same there shouldn't be a problem.
That said, it may be a mistake to rely on hash functions for this feature
(or maybe longer/64 bit hashes should be used)
On Sun, Feb 28, 2016 at 6:43 AM, Bojidar Marinov [email protected]
wrote:
@nunodonato https://github.com/nunodonato ~ BTW, your solution might
(must) still have collisions. That's a general problem with hashing...
Maybe a better solution would be to compare strings directly, even after
the same-hash test passes [image: :smile:]Still, if it is better, we might include your hash function too.
—
Reply to this email directly or view it on GitHub
https://github.com/godotengine/godot/issues/3843#issuecomment-189832161.
I found another random false positive, "acR":
I guess we should both use hashes, and string comparison... or maybe the Dictionary
class already does it?
I'm checking the code again, I can't find anywhere a hash alone is being used..
Something must be wrong and I am being unable to see it:
here the hash is computed
https://github.com/godotengine/godot/blob/master/scene/gui/text_edit.cpp#L836
and here the value is obtained from the hash and the string
https://github.com/godotengine/godot/blob/master/core/hash_map.h#L401
as you can see above, there is a string comparison happening too, so unless I'm missing something, it makes no sense that "q0" or "acR" are reported as keywords.
We should add some kind of tag "paranormal investigator job".
We should add some kind of tag "paranormal investigator job".
Yeah, because that was actually a very StrRange bug.
Most helpful comment
Something must be wrong and I am being unable to see it:
here the hash is computed
https://github.com/godotengine/godot/blob/master/scene/gui/text_edit.cpp#L836
and here the value is obtained from the hash and the string
https://github.com/godotengine/godot/blob/master/core/hash_map.h#L401
as you can see above, there is a string comparison happening too, so unless I'm missing something, it makes no sense that "q0" or "acR" are reported as keywords.
We should add some kind of tag "paranormal investigator job".