-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slices and Strings comparisons #105
Slices and Strings comparisons #105
Conversation
Hash is not the most gas efficient way to do this. There's a native opcode for this:
|
SDEQ is, essentially, an abbreviation for Slice Data Equal. It does not account for refs at all. Use of hash covers both long (multi-cell) and short (single-cell) strings correctly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing more features 👍.
Would be great to
- have some runtime tests with
==
and!=
both for strings and (some other kinds of) slices; - add an entry to the changelog (to the
Changed
subsection).
Update: done
This PR introduces the ability to compare both slices and strings via
==
operation.For slice comparison, their hashes (calculated using
HASHSU
) can be compared directly.As for strings, they are essentially slices and can be compared similarly. However, there's a consideration with strings due to their potential for various serializations (e.g., a string can be split in the middle and continued in a subsequent reference, still constituting a valid string). Upon reviewing the implementation of the
String
type in Tact, it was determined to be deterministic: all slices in a 'snake' representation are completely filled, except for the last one. Therefore, the same slice comparison method is applicable to strings as well.