-
Notifications
You must be signed in to change notification settings - Fork 440
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
Platform: replace use of std::string with String and StringView #559
Conversation
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.
Err... it's not that simple 😅
And while at it, it'd be good to make corresponding changes in other application implementations, because otherwise e.g. switching between EmscriptenApplication
and GlfwApplication
may cause nasty behavioral differences.
... I guess I take over and finish this together with the other apps, eventually. Hopefully you don't need to rely on this too soon? :)
@@ -113,7 +113,7 @@ GlfwApplication::GlfwApplication(const Arguments& arguments, NoCreateT): | |||
else if(dpiScaling == "physical") | |||
_commandLineDpiScalingPolicy = Implementation::GlfwDpiScalingPolicy::Physical; | |||
#endif | |||
else if(dpiScaling.find_first_of(" \t\n") != std::string::npos) | |||
else if(dpiScaling.find(' ').data() || dpiScaling.find('\t').data() || dpiScaling.find('\n').data()) |
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.
What's up with the .data()
?
Actually, this change should wait until I expose an alternative to find_first_of()
. It's there, just not public.
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.
What's up with the .data()?
Ah, I guess you mean I could be using operator bool()
instead? I see now, that the only empty view ever returned here would be the nullptr one 👍
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.
Yeah that, but more like I should finish the API first so this doesn't need to be temporarily implemented via insufficient lacking APIs. Something like if(dpiScaling.containsAnyOf(...))
would be ideal.
8437538
to
f7fc0e0
Compare
@mosra Thanks for the review! This is more a "nice to have", since it will improve our compile times (eventually, when we're able to turn off I might also have a look at making these changes for EmscriptenApplication tomorrow. |
.. and SDL, and Android, and ... ;) |
Signed-off-by: Squareys <squareys@googlemail.com>
Signed-off-by: Squareys <squareys@googlemail.com>
f7fc0e0
to
4768ea6
Compare
Signed-off-by: Squareys <squareys@googlemail.com>
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.
Uh, I don't know but, like, the changes don't even compile 😅 I just gave up reviewing midway through because every change in the EmscriptenApplication
was wrong one way or another.
What's the point of even pushing such a commit. Sorry to be so harsh, but it's easier for me to just discard the whole PR and start over, figuring out the changes from scratch, than attempting to review what's here and risk that I accidentally overlook a unhandled corner case in what looks like a hasty find&replace operation.
std::string str = id; | ||
std::free(id); | ||
return str; | ||
return Containers::String{id, std::strlen(id), &std::free}; |
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.
The deleter takes a pointer and a size, so you can't just pass std::free()
here.
@@ -469,14 +467,14 @@ Vector2i EmscriptenApplication::framebufferSize() const { | |||
} | |||
#endif | |||
|
|||
void EmscriptenApplication::setWindowTitle(const std::string& title) { | |||
void EmscriptenApplication::setWindowTitle(const Containers::StringView title) { | |||
#pragma GCC diagnostic push | |||
#pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension" | |||
EM_ASM_({document.title = UTF8ToString($0);}, title.data()); |
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.
💥
#pragma GCC diagnostic push | ||
#pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension" | ||
EM_ASM_({document.title = UTF8ToString($0);}, title.data()); | ||
#pragma GCC diagnostic pop | ||
} | ||
|
||
void EmscriptenApplication::setContainerCssClass(const std::string& cssClass) { | ||
void EmscriptenApplication::setContainerCssClass(const Containers::StringView cssClass) { | ||
#pragma GCC diagnostic push | ||
#pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension" | ||
EM_ASM_({ |
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.
💥 here also
@@ -605,7 +603,7 @@ void EmscriptenApplication::setupCallbacks(bool resizable) { | |||
})); | |||
#pragma GCC diagnostic pop | |||
|
|||
std::string keyboardListeningElementString; | |||
Containers::StringView keyboardListeningElementString; |
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.
💥, again, and the +=
doesn't even compile.
I took your changes as a base for a6da074...53a74b5 and kept you as a co-author, but the changes are significantly different from what's in this PR. Tried to convince GitHub to show a diff between the two so you could see what additionally had to be done, but the best I got includes also a ton of other changes that happened since the PR was opened. Things worth mentioning:
|
Quick note, because we're not using See also emscripten-core/emscripten#12517. |
Yes, I'm aware, but apart from the unnecessary strlen it's the behavior I want, to not make it any longer than the originating
So you have your own implementation of this, based on emscripten-core/emscripten#12517, and call that instead? In my case I'm not sure I'd want to bother (providing a JS file with a non-shitty implementation, bundling it to all produced executables, all that extra pain...). The Stale Bot is a cancer, FFS. So many issues get just sweeped under the rug due to it. |
Hi @mosra!
Since all the std::string is removed elsewhere, it's now very worth removing it from
GlfwApplication.h
also!Best,
Jonathan
TODO