1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:44:58 +00:00

AK: Remove String-from-StringView optimization

We had an unusual optimization in AK::StringView where constructing
a StringView from a String would cause it to remember the internal
StringImpl pointer of the String.

This was used to make constructing a String from a StringView fast
and copy-free.

I tried removing this optimization and indeed we started seeing a
ton of allocation traffic. However, all of it was due to a silly
pattern where functions would take a StringView and then go on
to create a String from it.

I've gone through most of the code and updated those functions to
simply take a String directly instead, which now makes this
optimization unnecessary, and indeed a source of bloat instead.

So, let's get rid of it and make StringView a little smaller. :^)
This commit is contained in:
Andreas Kling 2021-04-17 01:18:39 +02:00
parent 94b247c5a9
commit 873da38d0e
4 changed files with 5 additions and 17 deletions

View file

@ -219,8 +219,6 @@ static inline char to_lowercase(char c)
bool equals_ignoring_case(const StringView& a, const StringView& b)
{
if (a.impl() && a.impl() == b.impl())
return true;
if (a.length() != b.length())
return false;
for (size_t i = 0; i < a.length(); ++i) {