Commit graph

3812 commits

Author SHA1 Message Date
InvalidUsernameException
1d63398cbd AK: Expose dump_backtrace() publicly for debugging purposes
At this point, I've repeatedly felt the desire to be able to log
stacktraces to be able to see more easily what kind of call-sites exist
for a given piece of code. So this commit exposes `dump_backtrace()` in
the header so it can be used for this purpose.
2025-05-06 10:03:57 -04:00
stelar7
93d7a29306 AK: Implement {first|last}_matching for Span 2025-05-06 11:16:01 +02:00
Andreas Kling
a453da2906 AK: Allow specifying HashSetExistingEntryBehavior in HashMap::set() 2025-05-03 17:33:54 +02:00
Timothy Flynn
8a80ff7b3b AK+LibJS: Use simdutf for all base64 operations
We were previously unable to use simdutf for base64 decoding operations
other than "loose". Upstream has added support for the "strict" and
"stop-before-partial" operations, so let's make use of them!
2025-05-03 11:21:10 -04:00
Andreas Kling
cf6e2531d9 AK: Make String::number() much faster for integer types
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Instead of going through String::formatted(), we now have a specialized
code path for base-10 serialization directly to UTF-8.

This is roughly 5-10x faster than the previous implementation, depending
on how many digits we end up outputting.

1.07x speedup on MicroBench/for-in-indexed-properties.js
2025-05-02 19:13:03 +02:00
Shannon Booth
23f3ecbe98 AK: Don't iterate through entire String for String::ends_with
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
2025-04-28 10:50:31 -04:00
Andreas Kling
580b892b9e AK: Demote VERIFY in NonnullRefPtr to ASSERT
NonnullRefPtr almost always has a non-null pointer internally, that's
what the class is for, after all! The one edge case where it has null
internally is after you move() it. But it's always a bug to use an
NNRP after moving from it, and we have clang-tidy yelling at us if
that ever happens.

Demoting this removes a gazillion overly paranoid null checks.
2025-04-28 10:39:42 -04:00
Aliaksandr Kalenik
cd9e491742 AK: Use TypedTransfer in Span::overwrite()
Using `__builtin_memmove` was unsafe if items in source buffer are not
trivially copyable.
2025-04-24 10:30:52 +02:00
Aliaksandr Kalenik
005551b530 AK: Fix out of bound access check in Span::overwrite()
Previously `data_size` (in bytes) was mistakenly compared with `size()`
that returns number of elements in a span.
2025-04-24 10:30:52 +02:00
Ali Mohammad Pur
eea81738cd AK+Everywhere: Recognise that surrogates in utf16 aren't all that common
For the slight cost of counting code points when converting between
encodings and a teeny bit of memory, this commit adds a fast path for
all-happy utf-16 substrings and code point operations.

This seems to be a significant chunk of time spent in many regex
benchmarks.
2025-04-23 07:56:02 -06:00
Tim Ledbetter
31dea89fe0 AK: Add lowest common multiple and greatest common divisor functions 2025-04-23 09:13:45 +01:00
Pavel Shliak
84e29f791c Revert "AK: Work around Apple Clang __builtin_subc codegen issue"
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This reverts commit 9d4dfc1061.
2025-04-22 22:31:28 -06:00
Jonne Ransijn
bb20a0d8f8 AK: Allow the Optional<T> move assignment operator to be trivial
This will change behaviour for moved-from `Optional<T>`s, since they
will now no longer clear their value if `T` is trivial. However, a
moved-from value should be considered to be in an unspecified state.
Use `Optional<T>::clear` or `Optional<T>::release_value` instead.
2025-04-22 21:19:31 -06:00
Jonne Ransijn
50bc6fb9d9 AK: Loosen the restrictions on non-copyable/non-movable containers
If a type is non-move constructible but move assignable,
its container type may still be move assignable.

Similairly, if a type is non-copy constructible but copy assignable,
its container type may still be copy assignable.
2025-04-22 21:19:31 -06:00
Jonne Ransijn
eff9d4881c AK: Add IsScalar to StdLibExtraDetails.h
This matches the behaviour of `std::is_scalar_v`
2025-04-22 21:19:31 -06:00
Jonne Ransijn
0d1ba5c37d AK: Add IsMemberPointer to StdLibExtraDetails.h
Does exactly what it says on the tin.
2025-04-22 21:19:31 -06:00
Jonne Ransijn
e37377600d AK: Allow Optional<{,Fly}String> to be used in constant expressions 2025-04-22 21:19:31 -06:00
Jonne Ransijn
a059ab4677 AK: Allow Optional<T> to be used in constant expressions 2025-04-22 21:19:31 -06:00
Jonne Ransijn
063be28e90 AK: Add IsOneOfIgnoringCVReference to StdLibExtraDetails.h
Much like `IsOneOfIgnoringCV`, some functions want to ignore both
cv-qualifiers _and_ references. Add a template and concept for it.
2025-04-22 21:19:31 -06:00
Ali Mohammad Pur
76f5dce3db LibRegex: Flatten capture group list in MatchState
This makes copying the capture group COWVector significantly cheaper,
as we no longer have to run any constructors for it - just memcpy.
2025-04-18 17:09:27 +02:00
Andrew Kaster
ad00306daf AK: Disallow constness laundering in RefPtr and NonnullRefPtr
This is a re-application of 3c7a0ef1ac

Co-Authored-By: Andreas Kling <andreas@ladybird.org>
2025-04-16 10:41:44 -06:00
Andrew Kaster
703abac9c8 AK: Add const_cast escape hatch for converting const T& to RefPtr<T>
There are parts of the codebase where properly const-correctifying the
the code would be a giant spaghetti mess, so add this loud workaround
to defer the refactoring for later.
2025-04-16 10:41:44 -06:00
Andreas Kling
0c93a07fb1 AK: Shrink Utf16View
Use a sentinel value instead of Optional for the cached length in code
points, shrinking Utf16View from 32 to 24 bytes.
2025-04-16 10:04:50 +02:00
Andreas Kling
7628ddfaf7 AK: Remove endianness override from Utf16View
Utf16View is now always in "host" endian mode. This makes it smaller
and less branchy for everyone!
2025-04-16 10:04:50 +02:00
Andreas Kling
0e9480b944 AK+LibTextCodec: Stop using Utf16View endianness override
This is preparation for removing the endianness override, since it was
only used by a single client: LibTextCodec.

While here, add helpers and make use of simdutf for fast conversion.
2025-04-16 10:04:50 +02:00
Aliaksandr Kalenik
247f7c5fcc AK: Add peek_some() to AllocatingMemoryStream
Same as read_some(), but doesn't move read position.
2025-04-15 18:48:53 +02:00
Andrew Kaster
5e7e6475c6 AK: Annotate [[no_unique_address]] members with NO_UNIQUE_ADDRESS macro 2025-04-15 02:19:06 -06:00
Andrew Kaster
864ddfb55d AK: Add macro to switch between no_unique_address attribute forms
Also add an escape hatch for completely disabling the annotation.
2025-04-15 02:19:06 -06:00
Andreas Kling
87ec5b32b0 LibRegex: Use ReadonlySpan to peek into OpCode_Compare LUTs
Some checks are pending
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
By the time we're executing bytecode, we know the the bytecode will be
flattened. This means we can use ReadonlySpan to look into it instead of
DisjointChunks::spans(), which allocates.
2025-04-14 17:40:13 +02:00
stelar7
6ec914c7f7 LibWeb/IDB: Add some debug output 2025-04-09 11:48:49 -06:00
Andreas Kling
b2779ad9f7 AK: Shrink Utf16View from 40 bytes to 32 bytes
This ends up making RegexStringView smaller, which means less stuff to
copy when forking in the regex engine.

Thanks to Leon for suggesting the [[no_unique_address]] trick!
2025-04-09 07:22:01 +02:00
Andreas Kling
697e87b7bd AK: Make ""_string and ""_fly_string literals skip UTF-8 validation
We still validate in an ASSERT, but let's not bother with this in
release builds.
2025-04-09 07:22:01 +02:00
rmg-x
92f5183ced AK+Meta: Remove unused class RecursionDecision 2025-04-08 09:13:33 +02:00
rmg-x
fcf3abd19c AK: Remove unused class DOSPackedTime 2025-04-08 09:13:33 +02:00
Timothy Flynn
1d9e226206 AK: Remove unused UTF-8 / other factory methods from ByteString 2025-04-07 17:44:38 +02:00
Timothy Flynn
3f439efe21 AK: Rename StringImpl to ByteStringImpl
StringImpl is very specific to ByteString. Let's rename it to match, to
avoid confusion with the StringBase and StringData classes.
2025-04-07 17:44:38 +02:00
Timothy Flynn
0a256b0a9a AK+Everywhere: Change StringView case conversions to return String
There's a bit of a UTF-8 assumption with this change. But nearly every
caller of these methods were immediately creating a String from the
resulting ByteString anyways.
2025-04-07 17:44:38 +02:00
Timothy Flynn
05627b6f45 AK: Remove unused ByteString titlecase/invert case conversions 2025-04-07 17:44:38 +02:00
Timothy Flynn
c8bb3030fd AK: Return NonnullRefPtr from StringImpl::create methods
None of these return a nullptr.
2025-04-07 17:44:38 +02:00
Timothy Flynn
f029ba6a29 AK: Improve performance of ASCII case conversions
Don't use a Vector to form the transformed string. We can construct the
string immediately and store the result in its buffer, and thus avoid a
double allocation.

In a synthetic benchmark, lowercasing a 500 character ASCII string
1 million times reduced from 550ms to 65ms on my machine.
2025-04-07 17:44:38 +02:00
Timothy Flynn
13d7d3a60d AK: Simplify ASCII case conversion implementations a bit
* Use `any_of` instead of manual loops

* Don't check if a code point is upper/lowercase twice. The check we
  are using is already present inside the case converter.

* Move StringImpl's implementation into ByteString. ByteString is its
  only user, so let's avoid some jumping around. The other ASCII case
  methods on StringImpl will soon also be removed.
2025-04-07 17:44:38 +02:00
Timothy Flynn
ee6b2db009 AK+LibURL+LibWeb: Use simdutf to validate ASCII strings
simdutf provides a vectorized ASCII validator, so let's use that instead
of looping over strings manually.
2025-04-06 11:05:58 -04:00
Timothy Flynn
7f37a8f60f AK: Add an AK::find helper to return a reference to the found value
This is often more convenient than dealing with iterators.

This commit includes a couple conversions to find_value as examples.
2025-04-06 13:45:10 +02:00
rmg-x
37998895d8 AK+Meta+LibCore+Tests: Remove unused SipHash implementation
This is a homegrown implementation that wasn't actually used in
dependent classes. If this is needed in the future, using OpenSSL would
probably be a better option.
2025-04-06 01:47:50 +02:00
rmg-x
6480e1a3fe AK+Tests: Add support for URI syntax in IPv6Address::from_string
This supports IPv6 strings that start with `[` and end with `]` in
accordance with RFC3986 which states:

A host identified by an Internet Protocol literal address, version 6
[RFC3513] or later, is distinguished by enclosing the IP literal
within square brackets ("[" and "]").  This is the only place where
square bracket characters are allowed in the URI syntax.
2025-04-05 14:26:09 -04:00
Andreas Kling
3cf50539ec LibJS: Make Value() default-construct the undefined value
The special empty value (that we use for array holes, Optional<Value>
when empty and a few other other placeholder/sentinel tasks) still
exists, but you now create one via JS::js_special_empty_value() and
check for it with Value::is_special_empty_value().

The main idea here is to make it very unlikely to accidentally create an
unexpected special empty value.
2025-04-05 11:20:26 +02:00
R-Goc
28d5d982ce Everywhere: Remove unused private fields
Some checks are pending
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This commit removes the -Wno-unusued-private-field flag, thus
reenabling the warning. Unused field were either removed or marked
[[maybe_unused]] when unsure.
2025-04-04 12:40:07 +02:00
Andrew Kaster
4ab89d8bbb AK: Add cxxCast template to allow Swift to perform simple checked casts
This is a workaround for the lack of support for imported class
hierarchies in Swift. Swift's ClangImporter doesn't tell the Swift
frontend about derived class relationships between imported types.
2025-04-03 16:47:48 -06:00
Andrew Kaster
08b27f7b6e AK: Mark Function as SWIFT_UNSAFE_REFERENCE
This allows us to import APIs that include a function without crashing
the frontend. Without this, it chokes on the move-only behavior of the
class.
2025-04-03 16:47:48 -06:00
Timothy Flynn
d403f02988 AK: Remove unused capacity field from StringData
This was added to be used with `kfree_sized` when we construct a String
from a StringBuilder. As of 53cac71cec, it
is unused, causing some compilers to raise a warning.

This reduces the size of StringData from 24 to 16 bytes.
2025-04-03 23:44:40 +02:00