summaryrefslogtreecommitdiff
path: root/AK
AgeCommit message (Collapse)Author
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
2021-12-21AK+Everywhere: Replace __builtin bit functionsNick Johnson
In order to reduce our reliance on __builtin_{ffs, clz, ctz, popcount}, this commit removes all calls to these functions and replaces them with the equivalent functions in AK/BuiltinWrappers.h.
2021-12-21AK: Add convert_to_uint_from_octalXavier Defrang
2021-12-21AK: Make DisjointChunks not query size() when there are no chunksAli Mohammad Pur
2021-12-21AK: Add Disjoint(Chunks Spans)::find(index)Ali Mohammad Pur
For when the may or may not be out of bounds.
2021-12-21LibC+AK: Implement all sorts of wprintf variantsAli Mohammad Pur
2021-12-20AK+LibMain: Improve formatter for AK::Error in userspaceAndreas Kling
Print the full associated string metadata by default (if available.)
2021-12-18AK: Speed up BitmapView::find_next_range_of_unset_bitsNick Johnson
While watching Andreas' most recent video, I noticed that this function only worked with 32 bit values, but was a serious performance bottleneck for the kernel. As such, I reworked it to use `size_t`, so it now can switch to 64-bit sweeps on 64-bit platforms. This caused test-js to go from 12.5 seconds hot to 11.5 seconds hot on my machine when running on KVM x86_64.
2021-12-18AK: Add BuiltinWrappers.hNick Johnson
The goal of this file is to enable C++ overloaded functions for standard builtin functions that we use. It contains fallback implementations for systems that do not have the builtins available.
2021-12-17AK: Fast path for single-element TypedTransfer::copykleines Filmröllchen
Co-Authored-By: Brian Gianforcaro <bgianf@serenityos.org>
2021-12-17AK: Bypass Buffered's buffer for large readskleines Filmröllchen
Before, if we couldn't read enough data out of the buffer, we would re- fill the buffer and recursively call read(), which in turn reads data from the buffer into the resliced target span. This incurs very intensive superflous memmove's when large chunks of data are read from a buffered stream. This commit changes the behavior so that when we exhaust the buffer, we first read any necessary additional data directly into the target, then fill up the buffer again. Effectively, this results in drastically reduced overhead from Buffered when reading large contiguous chunks. Of course, Buffered is designed to speed up data access patterns with small frequent reads, but it's nice to be able to combine both access patterns on one stream without penalties either way. The final performance gain is about an additional 80% of abench decoding speed.
2021-12-16AK: Make JsonValue::from_string("") return a null JsonValueAndreas Kling
This unbreaks the /var/run/utmp system which starts out as an empty string, and is then turned into an object by the first update. This isn't necessarily the best way for this to work, but it's how it used to work, so this just fixes the regression for now.
2021-12-16Kernel+LibC: Move errno definitions to Kernel/API/POSIXsin-ack
This fixes at least half of our LibC includes in the kernel. The source of truth for errno codes and their description strings now lives in Kernel/API/POSIX/errno.h as an enumeration, which LibC includes.
2021-12-16AK: Use __builtin_memmove for ByteBuffer and Span's overwritesin-ack
__builtin_memcpy will fail when the target area and the source area overlap. Using __builtin_memmove will handle this case as well.
2021-12-16AK+Tests: Use less space in ErrorOrBen Wiederhake
2021-12-15AK: Enable fast path for removal by hash-compatible key in HashMap/TableHendiadyoin1
2021-12-15AK: Add implied const qualifiers to the Json interfaceHendiadyoin1
As specified by clang-tidy.
2021-12-15AK: Use StringView as key-type when removing a Value from an JsonObjectHendiadyoin1
2021-12-15AK: Return `bool` in `JsonValue::as_bool()`Hendiadyoin1
2021-12-15AK+LibSanitizer: Add method to zero out a UBSAN SourceLocationAndrew Kaster
This is the same strategy that LLVM's compiler-rt uses to make sure that each UBSAN error is only reported once, when UBSAN is *not* deadly. Otherwise, each time we head through a UB codepath, we will log the same error over and over. That behavior just adds noise to the logs and makes it nearly impossible to run binaires that have some common code path with flagged UB in them. compiler-rt goes the extra step to make sure the "clear" action is atomic, but we don't really have that many multi-threaded apps gettting tested with UBSAN yet, so we can add that later.
2021-12-15AK: Convert JsonObject to use StringViews for lookupHendiadyoin1
Most of the Keys we use are compile-time strings anyway, there is no need to use the heap to pass them around.
2021-12-15AK: Allow hash-compatible key types in Hash[Table|Map] lookupHendiadyoin1
This will allow us to avoid some potentially expensive type conversion during lookup, like form String to StringView, which would allocate memory otherwise.
2021-12-15AK: Add the concept of hash-compatible typesHendiadyoin1
2021-12-15AK: Add a Concept for any String typeHendiadyoin1
2021-12-15AK: Add dedicated Traits for c-stringsHendiadyoin1
2021-12-15AK: Add helper to test for pointer and cv-pointer at the same timeHendiadyoin1
2021-12-15AK: Add a Decay helper for ConceptsHendiadyoin1
2021-12-12AK: Fix preprocessor OS checkMartin Blicha
Instead of checking __linux__ macro directly, the code should check if this macro is defined. This is already done correctly a couple of lines above. I ran into this when trying to build libjs-test262 on MacOS where I got the following error message error: "__linux__" is not defined, evaluates to 0 [-Werror=undef]
2021-12-11AK: Simplify `Array::back()` by checking for Size > 0Jelle Raaijmakers
We do not want `Array::max()` to be used here at all - we know the size at compile-time, after all.
2021-12-09AK: Add RefCountForwarder<T>Andreas Kling
This is a convenience template that implements reference count forwarding. This means that an object forwards ref() and unref() to another object. We can use this when two ref-counted objects need to keep each other alive. This situation poses two problems: - Using 2x RefPtr would cause a ref cycle and leak both objects. - Using 2x WeakPtr would allow one of them to be destroyed early. With RefCountForwarder, only one of the objects has a ref count. The object with the ref count points to the forwarding object by using a non-counting smart pointer (OwnPtr or NonnullOwnPtr). Thus, both objects are kept alive by the same ref count, and they can safely point to each other without worrying about disjoint lifetimes.
2021-12-07AK: Zero-pad automatically if formatting with precisionTim Schumacher
2021-12-05AK: Implement missing const getters in AK::Error, fix typoBen Wiederhake
Note that the return type for the non-const method error() changed. This is most likely an accident, hidden by the fact that ErrorType typically is Error.
2021-12-05AK: Implement Formatter for ErrorOr<>Ben Wiederhake
As the Formatter for Error already exists, this apparently was just accidentally omitted.
2021-12-05AK: Mark smart pointer classes as [[nodiscard]]Sam Atkins
This makes it an error to not do something with a returned smart pointer, which should help prevent mistakes. In cases where you do need to ignore the value, casting to void will placate the compiler. I did have to add comments to disable clang-format on a couple of lines, where it wanted to format the code like this: ```c++ private : NonnullRefPtr() = delete; ```
2021-12-01Kernel: Add VALIDATE_IS_X86 macroJames Mintram
2021-11-28LibIPC+IPCCompiler+AK: Make IPC value decoders return ErrorOr<void>Andreas Kling
This allows us to use TRY() in decoding helpers, leading to a nice reduction in line count.
2021-11-28AK: Stop Vector::extend from unnecessary reallocationkleines Filmröllchen
Previously, Vector::extend for a moved vector would move the other vector into this vector if this vector was empty, thereby throwing away existing allocated capacity. Therefore, this commit allows the move to only happen if this vector's capacity is too small to fit the other vector. This will also alleviate bugs where callers relied on the capacity to never shrink with calls to unchecked_append, extend and the like.
2021-11-28AK: Add Vector::unchecked_append for data pointerskleines Filmröllchen
This mirrors the existence of append() for data pointers and is very useful when the program needs to have a guarantee of no allocations, as is necessary for real-time audio.
2021-11-28AK: Expose Buffered's buffer size and underlying streamkleines Filmröllchen
2021-11-28AK: Allow to "get a result" from Result<void>Hendiadyoin1
This is to make Result<void> work inside TRY
2021-11-28AK: Remove unused static member of BitmapBen Wiederhake
This is a remnant of the Bitmap/BitmapView split.
2021-11-23AK: On macOS host builds, wrap unistd.h with missing extern "C"csb6
During the build process on macOS, multiple versions of <unistd.h> were being included (Apple's version and GCC's version). It appears that all other places #include the version from GCC, but in Platform.h the Apple header was being used. GCC's <unistd.h> is wrapped in `extern "C"`, while Apple's is not. This causes a conflicting declaration, so we need to wrap the #include with extern "C". Issue has been observed on macOS Mojave. See https://github.com/microsoft/vcpkg/issues/11320 for a similar issue.
2021-11-23LibCore+AK: Move MappedFile from AK to LibCoreAndreas Kling
MappedFile is strictly a userspace thing, so it doesn't belong in AK (which is supposed to be user/kernel agnostic.)