Repository navigation
feat: Add strong view aliases - #7194
Merged
Merged
Conversation
pajlada
reviewed
Aug 23, 2026
pajlada
approved these changes
Aug 23, 2026
pajlada
enabled auto-merge (squash)
August 23, 2026 11:33
invisibl3cat
pushed a commit
to invisibl3cat/chatterino2
that referenced
this pull request
Aug 23, 2026
We have some strong aliases/typedefs like `UserId`, `UserName`, `EmoteName`, etc. Currently, they wrap a `QString`. In some cases, we don't want to use owned types. Notably, when looking up items in a map. There, it would be fine to look them up by `QStringView`. However, `QStringView` isn't "tagged" to contain a user ID, username, etc. This PR adds `-View` types as "tagged" versions of `QStringView`. So now `EmoteName` has a corresponding `EmoteNameView`. The view can be created from the owned type, and they can be compared to each other. The containers don't know about this relationship - for example, `std::unordered_map<EmoteName, V>` doesn't know that you can do lookup by `EmoteNameView`. To tell them, we need to provide both a transparent hasher (i.e. a hasher working for both types) and a transparent comparator. For the hasher, there's `EmoteNameHash` which forwards to the `QStringView` hash. For the comparison, [`std::equal_to<>`](https://en.cppreference.com/cpp/utility/functional/equal_to_void) can be used. See the tests for examples. Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
pajlada
pushed a commit
that referenced
this pull request
Aug 28, 2026
#7194 added view types for our aliases and this PR uses them for emote lookup. Most of this only changes the parameter types. Notably, it makes `MessageBuilder::tryAppendEmote` and the input highlighter's `isEmote` accept a view. It's not much yet, since other parts still expect owned strings. Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
babicekmarek
pushed a commit
to babicekmarek/streamally-chatterino
that referenced
this pull request
Sep 14, 2026
We have some strong aliases/typedefs like `UserId`, `UserName`, `EmoteName`, etc. Currently, they wrap a `QString`. In some cases, we don't want to use owned types. Notably, when looking up items in a map. There, it would be fine to look them up by `QStringView`. However, `QStringView` isn't "tagged" to contain a user ID, username, etc. This PR adds `-View` types as "tagged" versions of `QStringView`. So now `EmoteName` has a corresponding `EmoteNameView`. The view can be created from the owned type, and they can be compared to each other. The containers don't know about this relationship - for example, `std::unordered_map<EmoteName, V>` doesn't know that you can do lookup by `EmoteNameView`. To tell them, we need to provide both a transparent hasher (i.e. a hasher working for both types) and a transparent comparator. For the hasher, there's `EmoteNameHash` which forwards to the `QStringView` hash. For the comparison, [`std::equal_to<>`](https://en.cppreference.com/cpp/utility/functional/equal_to_void) can be used. See the tests for examples. Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
babicekmarek
pushed a commit
to babicekmarek/streamally-chatterino
that referenced
this pull request
Sep 14, 2026
Chatterino#7194 added view types for our aliases and this PR uses them for emote lookup. Most of this only changes the parameter types. Notably, it makes `MessageBuilder::tryAppendEmote` and the input highlighter's `isEmote` accept a view. It's not much yet, since other parts still expect owned strings. Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We have some strong aliases/typedefs like
UserId,UserName,EmoteName, etc. Currently, they wrap aQString. In some cases, we don't want to use owned types. Notably, when looking up items in a map. There, it would be fine to look them up byQStringView. However,QStringViewisn't "tagged" to contain a user ID, username, etc.This PR adds
-Viewtypes as "tagged" versions ofQStringView. So nowEmoteNamehas a correspondingEmoteNameView. The view can be created from the owned type, and they can be compared to each other.The containers don't know about this relationship - for example,
std::unordered_map<EmoteName, V>doesn't know that you can do lookup byEmoteNameView. To tell them, we need to provide both a transparent hasher (i.e. a hasher working for both types) and a transparent comparator. For the hasher, there'sEmoteNameHashwhich forwards to theQStringViewhash. For the comparison,std::equal_to<>can be used. See the tests for examples.I didn't modify any uses of the types yet.