summaryrefslogtreecommitdiff
path: root/AK
AgeCommit message (Collapse)Author
2022-01-14AK: Make Variant::visit() prefer overloads accepting T const& over T&Ali Mohammad Pur
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-14AK+Everywhere: Make Variant::visit() respect the Variant's constnessAli Mohammad Pur
...and fix all the instances of visit() taking non-const arguments.
2022-01-13AK: Add ByteBuffer::{must_,}get_bytes_for_writing()sin-ack
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-13AK: Use Error::from_errno in adopt_nonnull_own_or_enomemsin-ack
This fails to build on Lagom otherwise.
2022-01-13AK: Explain why FixedArray has no move assignmentkleines Filmröllchen
2022-01-13Tests: Test FixedArray completelykleines Filmröllchen
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-13AK: Remove clear() from FixedArray and fixate its allocation guaranteeskleines Filmröllchen
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-13AK: Disable NoAllocationGuard on Lagomkleines Filmröllchen
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-12AK: Remove unnecessary null checks in RedBlackTreeAndreas Kling
2022-01-12AK: Implement StringView::for_each_split_viewBrian Gianforcaro
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-12AK: Rewrite StringView::split_view(char..), using StringViewBrian Gianforcaro
2022-01-11AK: Add AK::Time factory method to construct from individual time fieldsTimothy Flynn
2022-01-11AK: Redeclare a few AK::Time helpers as constexprTimothy Flynn
This is to allow using these methods within an upcoming constexpr factory method.
2022-01-11AK+Kernel: Remove one_ref_left() footgunAndreas Kling
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-11AK: Define a traits helper for case-insensitive StringView hashingTimothy Flynn
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-11AK+LibC+LibPthread: Introduce NoAllocationGuardkleines Filmröllchen
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-10LibGUI+AK: Add DRAG_DEBUG opt and put drag operations behind dbgln_ifMarcus Nilsson
No need to have this enabled all the time.
2022-01-09AK: Added human_readable_time() method for "unsaved changes" dialogsRafał Babiarz
2022-01-09AK/SIMD: Suppress psabi warnings and add explanatory commentStephan Unverwerth
2022-01-09AK: Add SIMDMath.h with vectorized version of math functionsStephan Unverwerth
2022-01-09AK: Add SIMDExtras.h with SIMD related functionsStephan Unverwerth
Adds a header to AK with helper functions for writing vectorized code. Co-authored-by: Hendiadyoin <leon2002.la@gmail.com>
2022-01-09AK: Add ByteBuffer::append(char)Maciej
2022-01-08AK: Reorder functions in FixedArray so that mutable comes before constcreator1creeper1
2022-01-08AK: Reorder access in FixedArray so that m_size comes before m_elementscreator1creeper1
2022-01-08AK+Everywhere: Make FixedArray OOM-safecreator1creeper1
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-08AK: Unbreak ref counting hooks in RefCountedAndreas Kling
Same fix as 5871072ed3f7b7f4c2492828e1ad7fe167cd16bd, but for userspace this time. Regressed in c4a0f01b02d84117e644f2aff4396bdac1bcf40d.
2022-01-08AK+Kernel: Use requires expression when invoking ref counting hooksAndreas Kling
Replace some old-school template trickery with C++20 requires. :^)
2022-01-07Everywhere: Fix spelling mistakesmjz19910
2022-01-07AK: Use a full-period xorshift PRNG for double_hashSchlufi
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-07Everywhere: Fix many spelling errorsmjz19910
2022-01-05AK: Add Time.h helper to compute the number of days since epochTimothy Flynn
2022-01-05AK: Move TimeSpecType concept inside the AK namespaceTimothy Flynn
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-05AK: Make Vector::remove_all_matching() return removal successAndreas Kling
This matches the behavior of other remove_*_matching() functions.
2022-01-05AK: Make Hash{Map,Table}::remove_all_matching() return removal successAndreas Kling
These functions now return whether one or more entries were removed.
2022-01-05AK: Add HashMap::remove_all_matching(predicate)Andreas Kling
This removes all matching entries from a hash map in a single pass.
2022-01-05AK: Add HashTable::remove_all_matching(predicate)Andreas Kling
This removes all matching entries from a table in a single pass.
2022-01-05AK: Disable Vector insert/empend/prepend + a append overload in KernelBrian Gianforcaro
We have whittled away at the usages of these AK::Vector APIs in the Kernel. This change disables them from being visible when building the Kernel to make sure no new usages get added.
2022-01-05AK: Use MUST + try_empend so AK::Trie continues to compile in the kernelBrian Gianforcaro
2022-01-05AK: Use unchecked_append in AK::Stack, as we always validate the sizeBrian Gianforcaro
This removes one additional usage of Vector::append that stops us from disabling it when compiling the Kernel.
2022-01-04AK: Add `mix`Jelle Raaijmakers
2022-01-04AK: Fix UFixedBigInt comparison operatorsB0IIZZ
Instead of using the specified type U like we want, we were using the type T all along when comparing with smaller integers. This is now fixed.
2022-01-02AK: Include `utility` from the STD if we aren't replacing STDJames Puleo
If we didn't define our own `move` and `forward` and inject it into the `std` namespace, then we would error just after trying to `using` those, if no one has included it before. Now, we will include `utility` from the STD if we aren't replacing the `std`.
2021-12-30Kernel+AK: Eliminate a couple of temporary String allocationsDaniel Bertalan
2021-12-28Kernel: Remove the kmalloc_eternal heap :^)Andreas Kling
This was a premature optimization from the early days of SerenityOS. The eternal heap was a simple bump pointer allocator over a static byte array. My original idea was to avoid heap fragmentation and improve data locality, but both ideas were rooted in cargo culting, not data. We would reserve 4 MiB at boot and only ended up using ~256 KiB, wasting the rest. This patch replaces all kmalloc_eternal() usage by regular kmalloc().
2021-12-26AK: Don't include AK::demangle() in KERNEL buildsAndreas Kling
This was not used anywhere in the kernel anyway.
2021-12-26AK: Increase StringBuilder's inline buffer size from 128 to 256 bytesAndreas Kling
2021-12-25AK: Remove Variant<Ts...>::operator Variant<NewTs...>()Ali Mohammad Pur
This is an interface to downcast(), which degrades errors into runtime errors, and allows seemingly-correct-but-not-quite constructs like the following to appear to compile, but fail at runtime: Variant<NonnullRefPtr<T>, U> foo = ...; Variant<RefPtr<T>, U> bar = foo; The expectation here is that `foo` is converted to a RefPtr<T> if it contains one, and remains a U otherwise, but in reality, the NonnullRefPtr<T> variant is simply dropped on the floor, and the resulting variant becomes invalid, failing the assertion in downcast(). This commit adds a Variant<Ts...>(Variant<NewTs...>) constructor that ensures that no alternative can be left out at compiletime, for the users that were using this interface for merely increasing the number of alternatives (for instance, LibSQL's Value class).
2021-12-24AK: Add missing Array.h include to CheckedFormatString.hDaniel Bertalan
GCC 12 complains that iota_array is used before it's declared. GCC 11 works fine without it though.
2021-12-24AK: Make `Disjoint*::is_empty()` not call sizeMichel Hermier
This is a raffinement of 49cbd4dcca037336ad5e2e4fcb1e3cc613b46cce. Previously, the container was scanned to compute the size in the unhappy path. Now, using `all_of` happy and unhappy path should be fast.
2021-12-24AK: Add `DisjointChunkc::ensure_capacity`Michel Hermier