Commit graph

2291 commits

Author SHA1 Message Date
Lucas CHOLLET b0d51a6f36 AK: Fix erroneous move operators for SinglyLinkedList
This patch provides a proper implementation of the move operator and
delete the move assignment operator.

Those operators were introduced in #11888
2022-01-19 00:13:56 +01:00
Timothy Flynn b87e517deb AK: Remove now-unused AK::UnicodeUtils methods 2022-01-18 15:13:25 +00:00
Idan Horowitz 4774bed589 AK: Make Utf8View constexpr-constructible 2022-01-17 14:46:07 +00:00
Jelle Raaijmakers 11c807ebd1 LibGL+LibSoftGPU: Implement the stencil buffer
This implements an 8-bit front stencil buffer. Stencil operations are
SIMD optimized. LibGL changes include:

* New `glStencilMask` and `glStencilMaskSeparate` functions
* New context parameter `GL_STENCIL_CLEAR_VALUE`
2022-01-17 12:49:00 +01:00
Michel Hermier cb3cc6ec27 AK: Remove kfree definition 2022-01-16 11:18:04 +01:00
Michel Hermier 9039f8fb0f AK: Remove kcalloc definition 2022-01-16 11:18:04 +01:00
Matt Jacobson 47e8d58553 AK: Fix logic in String::operator>(const String&)
Null strings should not compare greater than non-null strings.

Add tests for >, <, >=, and <= comparison involving null strings.
2022-01-16 11:08:23 +01:00
Idan Horowitz 8a879e205b AK: Mark the error branch of the TRY() macro as unlikely
This results in a measurable (and free!) 2% improvement in test-js
run time.
2022-01-16 02:01:23 +02:00
creator1creeper1 4869dda79f AK: Explicitly name types in Iterator.h
In this particular case, auto is a footgun, because we are very
certain about the type that we want to return. const-correctness
could have been violated (as Vector did), because Iterator did not
enforce that the returned pointer was actually const if the Iterator
was an Iterator over a const container.
2022-01-16 00:38:21 +03:30
creator1creeper1 6484d42933 AK: Make Vector more const-correct by using RemoveReference<T>
Methods marked as const should always only return Foo const&, never
Foo&. Previously, this only worked correctly with Foo, but not with
Foo&: If someone fetched a T const&, this would have been expanded
to Foo& const& which is just Foo&. Therefore, they were able to modify
the elements of the Vector, even though it was marked as const.
This commit fixes that by introducing VisibleType as an alias for
RemoveReference<T> and using it throughout Vector.

There are also other cases where we don't require a mutable reference
to the underlying type, only a const reference (for example in a find
operation). In these cases, we now also correctly expand the type
to Foo const&.
2022-01-16 00:38:21 +03:30
creator1creeper1 64778f9e69 AK: Add a constructor from Span for FixedArray
This is particularly useful in the Kernel, where the physical pages of
a VMObject are stored as a FixedArray but often passed around as a Span
from which a new FixedArray should be cloned.
2022-01-15 22:16:00 +02:00
creator1creeper1 0362b15895 AK: Add a constructor from C-style arrays for FixedArray
We really want to be able to construct FixedArray from a list of
non-copyable but movable objects. This constructor is useful for
such things.
2022-01-15 22:16:00 +02:00
Lucas CHOLLET 1222eba0fb AK: Explicitly define copy and assignment operator for SinglyLinkedList
Defined operators:
 - SinglyLinkedList(const SinglyLinkedList&) - deleted
 - SinglyLinkedList(SinglyLinkedList&&) - defaulted
 - SinglyLinkedList& operator=(const SinglyLinkedList&) - deleted
 - SinglyLinkedList& operator=(SinglyLinkedList&&) - defaulted
2022-01-15 01:44:12 +01:00
Timothy Flynn 820dc1fc53 AK: Use appropriate types in AK::Time::from_timestamp factory
Allow the provided year to be negative, and allow millisecond values
larger than 255.
2022-01-14 22:39:06 +01:00
kleines Filmröllchen be6418cc50 Everywhere: Use my new serenityos.org e-mail :^) 2022-01-14 11:54:09 +01:00
Ali Mohammad Pur 95b8c1745a AK: Make Variant::visit() prefer overloads accepting T const& over T&
This makes the following code behave as expected:

    Variant<int, String> x { some_string() };
    x.visit(
        [](String const&) {}, // Expectation is for this to be called
        [](auto&) {});
2022-01-14 11:35:40 +03:30
Ali Mohammad Pur 9de33629da AK+Everywhere: Make Variant::visit() respect the Variant's constness
...and fix all the instances of visit() taking non-const arguments.
2022-01-14 11:35:40 +03:30
sin-ack 28063de488 AK: Add ByteBuffer::{must_,}get_bytes_for_writing()
This is useful for writing new data at the end of a ByteBuffer. For
instance, with the Stream API:

    auto pending_bytes = TRY(stream.pending_bytes());
    auto receive_buffer = TRY(buffer.get_bytes_for_writing(
        pending_bytes));
    TRY(stream.read(receive_buffer));
2022-01-13 15:16:12 +03:30
sin-ack 9569841589 AK: Use Error::from_errno in adopt_nonnull_own_or_enomem
This fails to build on Lagom otherwise.
2022-01-13 15:16:12 +03:30
kleines Filmröllchen 068aea660c AK: Explain why FixedArray has no move assignment 2022-01-13 11:17:44 +01:00
kleines Filmröllchen 594bbbf020 Tests: Test FixedArray completely
Except for tangential accessors such as data(), there is no more feature
of FixedArray that is untested after this large expansion of its test
cases. These tests, with the help of the new NoAllocationGuard, also
test the allocation contract that was fixated in the last commit.

Hopefully this builds confidence in future Kernel uses of FixedArray
as well as its establishment in the real-time parts of the audio
subsystem. I'm excited :^)
2022-01-13 11:17:44 +01:00
kleines Filmröllchen 1d144ed6fc AK: Remove clear() from FixedArray and fixate its allocation guarantees
FixedArray always *almost* had the following allocation guarantees:
There is (possibly) one allocation in the constructor and one (or more)
deallocation(s) in the destructor. No other operation allocates or
deallocates. With this removal of the public clear() method, which
nobody except the test used anyways, those guarantees are now completely
true and furthermore fixated with an explanatory comment.
2022-01-13 11:17:44 +01:00
kleines Filmröllchen 9bf2d0b718 AK: Disable NoAllocationGuard on Lagom
Because we don't have our LibC on Lagom, the allocation guard global
flag doesn't exist and NoAllocationGuard fails to build on Lagom.
Whoops. For now, just disable NoAllocationGuard's functionality here.
2022-01-13 11:17:44 +01:00
Andreas Kling a702b6ec42 AK: Remove unnecessary null checks in RedBlackTree 2022-01-12 14:52:47 +01:00
Brian Gianforcaro 142e099001 AK: Implement StringView::for_each_split_view
StringView::for_each_split_view allows you to process the splits in a
StringView without needing to allocate a Vector<StringView> to store
each of the parts.

Since we migrated the implementation from the normal split_view path, we
can also re-implement split_view in terms of for_each_split_view.
2022-01-12 13:03:44 +01:00
Brian Gianforcaro cd42f64bc7 AK: Rewrite StringView::split_view(char..), using StringView 2022-01-12 13:03:44 +01:00
Timothy Flynn 2b5840296a AK: Add AK::Time factory method to construct from individual time fields 2022-01-11 23:56:35 +01:00
Timothy Flynn 548643bcc9 AK: Redeclare a few AK::Time helpers as constexpr
This is to allow using these methods within an upcoming constexpr
factory method.
2022-01-11 23:56:35 +01:00
Andreas Kling a4b4b358ff AK+Kernel: Remove one_ref_left() footgun
This mechanism was unsafe to use in any multithreaded context, since
the hook function was invoked on a raw pointer *after* decrementing
the local ref count.

Since we don't use it for anything anymore, let's just get rid of it.
2022-01-11 01:12:16 +01:00
Timothy Flynn 3dccaa39d8 AK: Define a traits helper for case-insensitive StringView hashing
Currently, we define a CaseInsensitiveStringTraits structure for String.
Using this structure for StringView involves allocating a String from
that view, and a second string to convert that intermediate string to
lowercase.

This defines CaseInsensitiveStringViewTraits (and the underlying helper
case_insensitive_string_hash) to avoid allocations.
2022-01-11 00:36:45 +01:00
kleines Filmröllchen 2f50d8f4d3 AK+LibC+LibPthread: Introduce NoAllocationGuard
NoAllocationGuard is an RAII stack guard that prevents allocations
while it exists. This is done through a thread-local global flag which
causes malloc to crash on a VERIFY if it is false. The guard allows for
recursion.

The intended use case for this class is in real-time audio code. In such
code, allocations are really bad, and this is an easy way of dynamically
enforcing the no-allocations rule while giving the user good feedback if
it is violated. Before real-time audio code is executed, e.g. in LibDSP,
a NoAllocationGuard is instantiated. This is not done with this commit,
as currently some code in LibDSP may still incorrectly allocate in real-
time situations.

Other use cases for the Kernel have also been added, so this commit
builds on the previous to add the support both in Userland and in the
Kernel.
2022-01-11 00:08:58 +01:00
Marcus Nilsson 4459cb33ed LibGUI+AK: Add DRAG_DEBUG opt and put drag operations behind dbgln_if
No need to have this enabled all the time.
2022-01-10 14:23:04 +01:00
Rafał Babiarz 0012c03eb5 AK: Added human_readable_time() method for "unsaved changes" dialogs 2022-01-09 20:25:48 -08:00
Stephan Unverwerth f9c5c120f6 AK/SIMD: Suppress psabi warnings and add explanatory comment 2022-01-09 21:03:08 +01:00
Stephan Unverwerth 444a15bad3 AK: Add SIMDMath.h with vectorized version of math functions 2022-01-09 16:21:13 +03:30
Stephan Unverwerth 7adcdecc7b AK: Add SIMDExtras.h with SIMD related functions
Adds a header to AK with helper functions for writing vectorized code.

Co-authored-by: Hendiadyoin <leon2002.la@gmail.com>
2022-01-09 16:21:13 +03:30
Maciej ad2551e6b8 AK: Add ByteBuffer::append(char) 2022-01-09 00:18:46 +01:00
creator1creeper1 f73afbb5ae AK: Reorder functions in FixedArray so that mutable comes before const 2022-01-08 22:54:05 +01:00
creator1creeper1 18a2685c6a AK: Reorder access in FixedArray so that m_size comes before m_elements 2022-01-08 22:54:05 +01:00
creator1creeper1 3c05261611 AK+Everywhere: Make FixedArray OOM-safe
FixedArray now doesn't expose any infallible constructors anymore.
Rather, it exposes fallible methods. Therefore, it can be used for
OOM-safe code.
This commit also converts the rest of the system to use the new API.
However, as an example, VMObject can't take advantage of this yet,
as we would have to endow VMObject with a fallible static
construction method, which would require a very fundamental change
to VMObject's whole inheritance hierarchy.
2022-01-08 22:54:05 +01:00
Andreas Kling 0e70759271 AK: Unbreak ref counting hooks in RefCounted
Same fix as 5871072ed3, but for userspace
this time. Regressed in c4a0f01b02.
2022-01-08 19:38:00 +01:00
Andreas Kling c4a0f01b02 AK+Kernel: Use requires expression when invoking ref counting hooks
Replace some old-school template trickery with C++20 requires. :^)
2022-01-08 16:31:14 +01:00
mjz19910 10ec98dd38 Everywhere: Fix spelling mistakes 2022-01-07 15:44:42 +01:00
Schlufi 55a7738837 AK: Use a full-period xorshift PRNG for double_hash
The previous implementation had some pretty short cycles and two fixed
points (1711463637 and 2389024350). If two keys hashed to one of these
values insertions and lookups would loop forever.
This version is based on a standard xorshift PRNG with period 2**32-1.
The all-zero state is usually forbidden, so we insert it into the cycle
at an arbitrary location.
2022-01-07 12:34:44 +01:00
mjz19910 3102d8e160 Everywhere: Fix many spelling errors 2022-01-07 10:56:59 +01:00
Timothy Flynn bb9db5937a AK: Add Time.h helper to compute the number of days since epoch 2022-01-05 20:05:12 +01:00
Timothy Flynn 0c75a14b4f AK: Move TimeSpecType concept inside the AK namespace
This is just to allow removing the 'clang-format off' directive. This
concept is only used within this header, so it doesn't need to be in the
global namespace.
2022-01-05 20:05:12 +01:00
Andreas Kling 558fb0a04a AK: Make Vector::remove_all_matching() return removal success
This matches the behavior of other remove_*_matching() functions.
2022-01-05 18:57:14 +01:00
Andreas Kling 5279a04c78 AK: Make Hash{Map,Table}::remove_all_matching() return removal success
These functions now return whether one or more entries were removed.
2022-01-05 18:57:14 +01:00
Andreas Kling 376e5ef912 AK: Add HashMap::remove_all_matching(predicate)
This removes all matching entries from a hash map in a single pass.
2022-01-05 18:57:14 +01:00