Skip to content

Conversation

@nielsdos
Copy link
Member

@nielsdos nielsdos commented Feb 2, 2023

This abstracts away, and cleans up, the flag handling for properties of
strings that hold when concatenating two strings if they both hold that
property. (These macros also work with simply copies of strings because
a copy of a string can be considered a concatenation with the empty
string.) This gets rid of some branches and some repetitive code, and
leaves room for adding more flags like these in the future.

This also adds the UTF-8 flag for str_repeat (if the input is UTF-8).

cc @Girgias @alexdowad (because you both worked on this before)

@alexdowad
Copy link
Contributor

Nice!

I would just suggest adding a code comment to ZSTR_COPYABLE_CONCAT_PROPERTIES to explain the idea behind this macro. (If I was reading this code without context, I would find it mysterious at first.)

@nielsdos
Copy link
Member Author

nielsdos commented Feb 2, 2023

Thanks, I added some comments.

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's a smarter way of doing it, I always forget that one can achieve this by using a bitwise AND.

…nating two strings

This abstracts away, and cleans up, the flag handling for properties of
strings that hold when concatenating two strings if they both hold that
property. (These macros also work with simply copies of strings because
a copy of a string can be considered a concatenation with the empty
string.) This gets rid of some branches and some repetitive code, and
leaves room for adding more flags like these in the future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants