Commit graph

2426 commits

Author SHA1 Message Date
Lenny Maiorani 5b59375a56 AK: Fix implicit and narrowing conversions in Base64 2022-03-16 16:19:53 +00:00
Lenny Maiorani 8d1d4d4f09 AK: Make static constexpr variables to avoid stack copy in Base64
Alphabet and lookup table are created and copied to the stack on each
call. Create them and store them in static memory.
2022-03-16 16:19:53 +00:00
Daniel Bertalan e3eb68dd58 AK+Kernel: Avoid double memory clearing of HashTable buckets
Since the allocated memory is going to be zeroed immediately anyway,
let's avoid redundantly scrubbing it with MALLOC_SCRUB_BYTE just before
that.

The latest versions of gcc and Clang can automatically do this malloc +
memset -> calloc optimization, but I've seen a couple of places where it
failed to be done.

This commit also adds a naive kcalloc function to the kernel that
doesn't (yet) eliminate the redundancy like the userland does.
2022-03-15 11:56:46 +01:00
Hendiadyoin1 cd21e03225 AK+Everywhere: Add sincos and use it in some places
Calculating sin and cos at once is quite a bit cheaper than calculating
them individually.
x87 has even a dedicated instruction for it: `fsincos`.
2022-03-15 11:39:42 +01:00
Timothy Flynn c12cfe83b7 AK: Allow creating a Vector from any Span of the same underlying type
This allows, for example, to create a Vector from a subset of another
Vector.
2022-03-14 16:33:15 +01:00
Brian Gianforcaro 390666b9fa AK: Add naive implementations of AK::timing_safe_compare
For security critical code we need to have some way of performing
constant time buffer comparisons.
2022-03-13 19:08:58 -07:00
Tim Schumacher dd71754d10 AK: Properly parse unimplemented format length specifiers
This keeps us from stopping early and not rendering the argument at all.
2022-03-12 12:42:07 +03:30
Sam Atkins 2362cc2943 AK: Remove unused String[256] from JsonParser
This shrinks the JsonParser class from 2072 bytes to 24. :^)
2022-03-10 18:43:09 +01:00
Sam Atkins a451810599 AK: Print a better error message when missing a SourceGenerator key
Previously, if you forgot to set a key on a SourceGenerator, you would
get this less-than-helpful error message:

> Generate_CSS_MediaFeatureID_cpp:
  /home/sam/serenity/Meta/Lagom/../../AK/Optional.h:174: T
  AK::Optional<T>::release_value() [with T = AK::String]: Assertion
  `m_has_value' failed.

Now, it instead looks like this:

> No key named `name:titlecase` set on SourceGenerator
  Generate_CSS_MediaFeatureID_cpp:
  /home/sam/serenity/Meta/Lagom/../../AK/SourceGenerator.h:44:
  AK::String AK::SourceGenerator::get(AK::StringView) const: Assertion
  `false' failed.
2022-03-09 23:06:30 +01:00
Federico Guerinoni 0aed2f0f86 AK: Add reverse iterator as member 2022-03-09 17:16:28 +01:00
Federico Guerinoni f34fff852b AK: Implement wrapper for reverse range for loop
Now it is possible to use range for loop in reverse mode for a
container.
```
	for (auto item : in_reverse(vector))
```
2022-03-09 17:16:28 +01:00
Federico Guerinoni a54e20d958 AK: Implement ReverseIterator for NonnullPtrVector 2022-03-09 17:16:28 +01:00
Federico Guerinoni b0e74a3fd3 AK: Implement reverse iterator for Vector class 2022-03-09 17:16:28 +01:00
Federico Guerinoni 74650b4e32 AK: Add generic reverse iterator for containers 2022-03-09 17:16:28 +01:00
Tom 2f0e3da142 AK: Add IPv6Address class
This is the IPv6 counter part to the IPv4Address class and implements
parsing strings into a in6_addr and formatting one as a string. It
supports the address compression scheme as well as IPv4 mapped
addresses.
2022-03-08 23:05:44 +01:00
Vrins 73ade62d4f AK: Add float support for JsonValue and JsonObjectSerializer 2022-03-08 22:09:52 +01:00
Vrins ae1cd4b448 AK: Add to_double() to JsonValue 2022-03-08 22:09:52 +01:00
Andreas Kling 9d8da1697e AK: Automatically shrink HashTable when removing entries
If the utilization of a HashTable (size vs capacity) goes below 20%,
we'll now shrink the table down to capacity = (size * 2).

This fixes an issue where tables would grow infinitely when inserting
and removing keys repeatedly. Basically, we would accumulate deleted
buckets with nothing reclaiming them, and eventually deciding that we
needed to grow the table (because we grow if used+deleted > limit!)

I found this because HashTable iteration was taking a suspicious amount
of time in Core::EventLoop::get_next_timer_expiration(). Turns out the
timer table kept growing in capacity over time. That made iteration
slower and slower since HashTable iterators visit every bucket.
2022-03-07 00:08:22 +01:00
Andreas Kling eb829924da AK: Remove return value from HashTable::remove() and HashMap::remove()
This was only used by remove_all_matching(), where it's no longer used.
2022-03-07 00:08:22 +01:00
Andreas Kling 623bdd8b6a AK: Simplify HashTable::remove_all_matching()
Just walk the table from start to finish, deleting buckets as we go.
This removes the need for remove() to return an iterator, which is
preventing me from implementing hash table auto-shrinking.
2022-03-07 00:08:22 +01:00
Linus Groh 1719862d12 LibWeb: Hide some debug logging behind CANVAS_RENDERING_CONTEXT_2D_DEBUG
This can be quite noisy and isn't generally useful information.
2022-03-04 23:03:29 +01:00
Peter Ross 34108547b6 AK: Print NaN and infinite numbers in PrintfImplementation 2022-03-02 11:40:37 +01:00
Lucas CHOLLET 39bfc48ea7 AK: Add Time::from_ticks()
This helper allows Time to be constructed from a tick count and a ticks
per second value.
2022-02-28 20:09:37 +01:00
Timur Sultanov 406b3fc3fe AK: Correctly process precision modifiers in printf 2022-02-28 14:08:24 +01:00
kleines Filmröllchen 98058f7efe AK: Add FixedPoint base 2 logarithm
The log base 2 is implemented using the binary logarithm algorithm
by Clay Turner (see the link in the comment)
2022-02-28 13:59:31 +01:00
kleines Filmröllchen 30002c2ccb AK: Add bit shift to FixedPoint 2022-02-28 13:59:31 +01:00
kleines Filmröllchen 5d6e3441fe AK: Fix FixedPoint to integral comparisons
Add tests to ensure that the fixed point numbers compare correctly to
integrals
2022-02-28 13:59:31 +01:00
Idan Horowitz feb00b7105 Everywhere: Make JSON serialization fallible
This allows us to eliminate a major source of infallible allocation in
the Kernel, as well as lay down the groundwork for OOM fallibility in
userland.
2022-02-27 20:37:57 +01:00
Idan Horowitz 9da8c78133 AK: Add a try variant of StringBuilder::append_escaped_for_json
This will allow us to make a fallible version of the JSON serializers.
2022-02-27 20:37:57 +01:00
kleines Filmröllchen 7e18e6e37b AK: Skip over initial empty chunks in DisjointChunks
This will be caught by new test cases: when the initial chunk is empty,
a dereference before calling operator++ on the iterator will crash as
the initial chunk's size is never checked.
2022-02-27 00:11:14 +03:30
kleines Filmröllchen 4ec599aae5 AK: Make DisjointChunks support FixedArray
This extracts the shatter_chunk logic, because it needs to be different
for FixedArray.
2022-02-27 00:11:14 +03:30
kleines Filmröllchen ee9eef1fa8 AK: Make DisjointChunk::append move the new chunk
Previously, although we were taking a moved chunk, we still copied it
into our chunk list. This makes DisjointChunk compatible with containers
that don't have a copy constructor but a move constructor.
2022-02-27 00:11:14 +03:30
kleines Filmröllchen 6e5bf7ac6f AK: Export DisjointSpans into the global namespace
I think we just forgot when we added it.
2022-02-27 00:11:14 +03:30
kleines Filmröllchen 75eb5e7984 AK: Add at() indexing methods to FixedArray 2022-02-27 00:11:14 +03:30
kleines Filmröllchen 09df8f812a AK: Allow creating a FixedArray from an initializer list 2022-02-27 00:11:14 +03:30
kleines Filmröllchen 65f34504e9 AK: Add FixedArray::is_empty()
This also exists on Vector, and although it's less needed here, it's
perfectly reasonable to have.
2022-02-27 00:11:14 +03:30
Arne Elster b7110c2a34 AK: Add constructor to create Span from Array
It's a convenience constructor. But it also seems more consistent
to allow a Span being made from both raw and managed arrays.
2022-02-26 16:01:26 +01:00
Arne Elster 6a0cac7cdb AK: Array can tell its inner type
Array should be able to tell the type of the elements it contains.
2022-02-26 16:01:26 +01:00
Andreas Kling f2663f477f AK: Ignore whitespace while decoding base64
This matches how other implementations behave.

1% progression on ACID3. :^)
2022-02-25 19:54:13 +01:00
Andreas Kling dd7eb3d6d8 AK: Add String::split_view(Function<bool(char)>)
This allows you to split around a custom separator, and enables
expressive code like this:

    string.split_view(is_ascii_space);
2022-02-25 19:38:31 +01:00
Linus Groh 1752f7720e AK: Add forward declaration for Utf8CodePointIterator 2022-02-23 21:53:30 +00:00
Linus Groh b253bca807 AK: Add optional format string parameter to String{,Builder}::join()
Allow specifying a custom format string that's being used for each item
instead of hardcoding "{}".
2022-02-23 21:53:30 +00:00
Linus Groh f8ff8c8dd6 AK: Add Traits<Span<T>>::hash() 2022-02-23 21:53:30 +00:00
kleines Filmröllchen 604309327e AK: Add the Fundamental concept 2022-02-23 00:42:49 +00:00
kleines Filmröllchen 7418bdb85f AK: Prevent Atomic with complex types
This would throw some really weird linker errors, so let's prevent it
from happening instead!
2022-02-23 00:42:49 +00:00
Max Wipfli d29d9462e9 AK: Suppress clang-tidy warning on TODO()
This adds a NOLINT directive to the definition of the TODO() macro.
clang-tidy wants the assert replaced with a static_assert, since the
macro simply resolves to assert(false). This is obviously nonsensical,
since we want the code to still compile even with TODO().

The same fix has already been implemented for VERIFY_NOT_REACHED().
2022-02-21 19:01:16 +02:00
Andreas Kling 4b900bc100 AK: Add fast path in String::trim() and String::trim_whitespace()
If the trimmed string would be the entire string, just return *this
instead of creating a new StringImpl.
2022-02-19 14:45:59 +01:00
Andreas Kling 2dd3b54827 AK: Make CaseInsensitiveStringTraits allocation-free
Instead of calling String::to_lowercase(), do case-insensitive hashing
and comparison.
2022-02-19 14:45:59 +01:00
Gunnar Beutner 7a65bd8efb AK: Don't use x86 assembly when building for non-x86 targets
This allows Lagom to be built successfully for Apple M1.

Fixes #12644.
2022-02-19 13:13:22 +02:00
Ben Abraham ae346cff6b LibWeb: Add partially functioning Worker API
Add a partial implementation of HTML5 Worker API.
Messages can be sent from the inner context externally.
2022-02-17 22:45:21 +01:00