Commit graph

47 commits

Author SHA1 Message Date
Dan Klishch fa52f68142 AK: Store data in FlyString as StringBase
Unfortunately, it is not clear to me how to split this commit into
several atomic ones.
2024-01-21 16:16:15 -07:00
Shannon Booth 8c8ea86729 AK: Add FlyString::starts_with_bytes and FlyString::ends_with_bytes
Mirroring the API for String
2023-11-07 11:33:41 +01:00
Andreas Kling e4d14e1afc AK: Add FlyString::operator<=>(FlyString const&)
Same as String already has.
2023-09-06 11:29:03 -04:00
Andreas Kling 1e820385d9 AK: Add case-insensitive hashing for the new String classes
Bringing over this functionality from DeprecatedString.
2023-09-06 11:29:03 -04:00
Sam Atkins f527e55046 AK: Allow case-insensitive FlyString/StringView comparison 2023-09-05 14:27:23 +02:00
Kenneth Myhra e28a6d5da4 AK: Add FlyString::from_deprecated_fly_string()
Let's add FlyString::from_deprecated_fly_string() so we can use it
instead of FlyString::from_utf8(). This will make it easier to detect
potential unncessary allocations as we transfer to FlyString.
2023-03-11 18:32:33 +00:00
Andreas Kling a504ac3e2a Everywhere: Rename equals_ignoring_case => equals_ignoring_ascii_case
Let's make it clear that these functions deal with ASCII case only.
2023-03-10 13:15:44 +01:00
Andreas Kling d517e7fb3a AK: Make FlyString::hash() use the cached hash in StringData if possible
This avoids rehashing the string every time.
2023-03-09 21:54:59 +01:00
Andreas Kling 629b6462dc AK: Add FlyString::equals_ignoring_ascii_case()
This is similar to equals_ignoring_case() but only cares about ASCII
case insensitivity.
2023-03-08 13:19:15 +01:00
Kenneth Myhra 03ceca4ca1 AK: Add FlyString::to_deprecated_fly_string()
This adds the conversion function to_deprecated_fly_string() to enable
conversion from new FlyString to DeprecatedFlyString.
2023-03-05 18:25:59 +00:00
Sam Atkins a35fa553dd AK: Let FlyStrings be assigned from Strings 2023-02-15 12:48:26 -05:00
Timothy Flynn 1d4f287582 AK: Implement FlyString for the new String class
This implements a FlyString that will de-duplicate String instances. The
FlyString will store the raw encoded data of the String instance: If the
String is a short string, FlyString holds the String::ShortString bytes;
otherwise FlyString holds a pointer to the Detail::StringData.

FlyString itself does not know about String's storage or how to refcount
its Detail::StringData. It defers to String to implement these details.
2023-01-12 11:23:58 +01:00
Timothy Flynn f3db548a3d AK+Everywhere: Rename FlyString to DeprecatedFlyString
DeprecatedFlyString relies heavily on DeprecatedString's StringImpl, so
let's rename it to A) match the name of DeprecatedString, B) write a new
FlyString class that is tied to String.
2023-01-09 23:00:24 +00:00
Linus Groh 57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh 6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
davidot 6fd8e96d53 AK: Add to_{double, float} convenience functions to all string types
These are guarded with #ifndef KERNEL, since doubles (and floats) are
not allowed in KERNEL mode.
In StringUtils there is convert_to_floating_point which does have a
template parameter incase you have a templated type.
2022-10-23 15:48:45 +02:00
Idan Horowitz 086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Daniel Bertalan 5b3ba2d9ad AK: Implement FlyString's comparison operators in terms of StringView's 2022-01-29 23:08:27 +01:00
Andreas Kling 8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Andreas Kling c94c15d45c Everywhere: Replace AK::Singleton => Singleton 2021-08-08 00:03:45 +02:00
sin-ack 3abcfcc178 AK: Add a way to disable the trimming of whitespace in to_*int
This behavior might not always be desirable, and so this patch adds a
way to disable it.
2021-06-18 19:18:15 +01:00
Linus Groh 0a7e91329f Revert "Revert "AK: Always inline FlyString::view()""
This reverts commit f09216ac42.
This was supposed to be a local test only, didn't mean to push it. :^)
2021-06-06 08:05:49 +01:00
Linus Groh f09216ac42 Revert "AK: Always inline FlyString::view()"
This reverts commit 66f15c2e0c.
2021-06-06 01:58:09 +01:00
Andreas Kling 66f15c2e0c AK: Always inline FlyString::view() 2021-06-05 12:36:14 +02:00
Gunnar Beutner a4f320c76b AK: Allow inlining more string functions 2021-06-03 08:06:51 +02:00
Andreas Kling a4099fc756 AK: Try to avoid String allocation in FlyString(StringView)
If we're constructing a FlyString from a StringView, and we already
have a matching StringImpl in the table, use HashTable::find() to
locate the existing string without creating a temporary String.
2021-05-15 11:01:05 +02:00
Brian Gianforcaro 1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Linus Groh e265054c12 Everywhere: Remove a bunch of redundant 'AK::' namespace prefixes
This is basically just for consistency, it's quite strange to see
multiple AK container types next to each other, some with and some
without the namespace prefix - we're 'using AK::Foo;' a lot and should
leverage that. :^)
2021-02-26 16:59:56 +01:00
Andreas Kling 5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Sahan Fernando 37df4bbd90 AK: Generalize AK::String::to_int() for more types 2020-12-21 00:15:44 +01:00
Andreas Kling 3dbd5c98da AK: Use StringImpl::operator== in FlyString 2020-10-06 17:43:51 +02:00
Tom d89582880e Kernel: Switch singletons to use new Singleton class
MemoryManager cannot use the Singleton class because
MemoryManager::initialize is called before the global constructors
are run. That caused the Singleton to be re-initialized, causing
it to create another MemoryManager instance.

Fixes #3226
2020-08-25 09:48:48 +02:00
Andreas Kling 8925ad3fa0 Revert "Kernel: Move Singleton class to AK"
This reverts commit f0906250a1.
2020-08-22 16:34:49 +02:00
Andreas Kling 68580d5a8d Revert "AK: Get rid of make_singleton function"
This reverts commit 5a98e329d1.
2020-08-22 16:34:14 +02:00
Tom 5a98e329d1 AK: Get rid of make_singleton function
Just default the InitFunction template argument.
2020-08-22 10:46:24 +02:00
Tom f0906250a1 Kernel: Move Singleton class to AK 2020-08-22 10:46:24 +02:00
Luke a5ecb9bd6b AK: Add case insensitive version of starts_with 2020-07-21 01:08:32 +02:00
Andreas Kling 35329400b8 AK: Implement a slightly better FlyString::operator==(String)
This was showing up in Browser profiles, which is silly, so write a new
version that doesn't create a temporary String object.

There are a whole bunch of these and long-term it would be nice to find
a way to share all the very similar logic instead of duplicating it.
2020-06-16 19:19:30 +02:00
Andreas Kling fdfda6dec2 AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature:

- int StringType::to_int(bool& ok) const

And replace it with sensible new signature:

- Optional<int> StringType::to_int() const
2020-06-12 21:28:55 +02:00
Brian Gianforcaro 129462cca7 AK: Unify FlyString/StringView::ends_with implementation on StringUtils::ends_with
This creates a unified implementation of ends_with with case sensitivity
across String/StringView/FlyString.
2020-05-26 13:17:19 +02:00
Andreas Kling e4b9cf9b6c AK: Some FlyString improvements
We're now clever enough to notice when we're constructing a FlyString
from a String that is actually already a FlyString. :^)
2020-05-05 11:26:03 +02:00
Andreas Kling 76bb0fab2d AK: Make FlyString a little less hilariously unoptimized :^) 2020-04-06 08:26:26 +02:00
Andreas Kling 95cc4c7e74 AK: Add some string comparison operators
Some of these are very inefficient. It's nice to have some optimization
opportunities in the future though. :^)
2020-03-28 09:11:13 +01:00
Andreas Kling 7d862dd5fc AK: Reduce header dependency graph of String.h
String.h no longer pulls in StringView.h. We do this by moving a bunch
of String functions out-of-line.
2020-03-23 13:48:44 +01:00
Andreas Kling c4a6d6ae9f AK: Add FlyString::to_lowercase() and LogStream operator<<(FlyString) 2020-03-22 19:07:02 +01:00
Andreas Kling 26bc3d4ea0 AK: Add FlyString::equals_ignoring_case(StringView)
And share the code with String by moving the logic to StringUtils. :^)
2020-03-22 13:07:45 +01:00
Andreas Kling 4f72f6b886 AK: Add FlyString, a simple flyweight string class
FlyString is a flyweight string class that wraps a RefPtr<StringImpl>
known to be unique among the set of FlyStrings. The class is very
unoptimized at the moment.

When to use FlyString:

- When you want O(1) string comparison
- When you want to deduplicate a lot of identical strings

When not to use FlyString:

- For strings that don't need either of the above features
- For strings that are likely to be unique
2020-03-22 13:03:43 +01:00