summaryrefslogtreecommitdiff
path: root/AK
AgeCommit message (Collapse)Author
2021-06-29AK: Ensure StringBuilder capacity in String::reverseIdan Horowitz
2021-06-29AK: Add the to_ascii_base36_digit helper methodIdan Horowitz
2021-06-29AK: Use [[nodiscard]] in JsonObject and JsonArrayMax Wipfli
2021-06-29AK+Spreadsheet+LibWeb: Remove JsonObject::get_or()Max Wipfli
This removes JsonObject::get_or(), which is inefficient because it has to copy the returned value. It was only used in a few cases, some of which resulted in copying JsonObjects, which can become quite large.
2021-06-29AK: Add JsonObject::has_* methodsMax Wipfli
This adds methods to JsonObject to check if a key exists with a certain type. This simplifies code that validates whether a JsonObject has the expected structure.
2021-06-29AK+Everywhere: Change int to size_t in JsonObject and JsonArrayMax Wipfli
2021-06-29AK: Return const& from JsonObject::get()Max Wipfli
This adds a static JsonValue* s_null_value, which allows JsonObject::get to return a reference instaed of copying the return value. Since JsonValue is only 16 bytes, this seems like a reasonable compromise.
2021-06-29AK: Use OrderedHashMap in JsonObjectMax Wipfli
This changes JsonObject to use the new OrderedHashMap instead of an extra vector for tracking the insertion order. This also adds a default value for the KeyTraits template argument in OrderedHashMap. Furthermore, it fixes two cases where code iterating over a JsonObject relied on the value argument being copied before invoking the callback.
2021-06-29AK: Make JsonValue::as_string_or() constMax Wipfli
2021-06-29AK: Use east const style in Json{Array,Object}.hMax Wipfli
2021-06-29AK: Store the 'extra' field of ScopeLogger as StringItamar
It was previously stored as a StringView, which prevented us from using temporary strings in the 'extra' argument. The performance hit doesn't really matter because ScopeLogger is used exclusively for debugging.
2021-06-29AK: Don't colorize the 'extra' field of ScopeLogger in dbgln()Itamar
It's easier to spot it in the debug logs this way :)
2021-06-28Kernel: Fix memset() on x86_64Gunnar Beutner
Previously memset() only set half of the bytes to the requested value.
2021-06-28AK: Add and use the RemoveCVReference<T> type traitAli Mohammad Pur
2021-06-27AK: Make the constexpr StringView methods actually constexprAli Mohammad Pur
Also add some tests to ensure that they _remain_ constexpr. In general, any runtime assertions, weirdo C casts, pointer aliasing, and such shenanigans should be gated behind the (helpfully newly added) AK::is_constant_evaluated() function when the intention is to write constexpr-capable code. a.k.a. deliver promises of constexpr-ness :P
2021-06-27AK: Add explicit Variant conversion operatorsAli Mohammad Pur
This allows converting between Variants of different types with less pain.
2021-06-26AK: Undo bogus Variant::downcast() renameAndreas Kling
I accidentally renamed these to verify_cast() when doing the global AK::downcast() rename.
2021-06-25AK: Add NOTE about VERIFY in Function::clearItamar
2021-06-25AK: Add big endian bit reading to InputBitStreamkleines Filmröllchen
The existing InputBitStream methods only read in little endian, as this is what the rest of the system requires. Two new methods allow the input bitstream to read bits in big endian as well, while using the existing state infrastructure. Note that it can lead to issues if little endian and big endian reads are used out of order without aligning to a byte boundary first.
2021-06-25Toolchain: Add the AFLACLOADER_DEBUG macrokleines Filmröllchen
This enables FLAC debugging output, which is used with the new FLAC loader introduced in later commits.
2021-06-24AK: Rename downcast<T> => verify_cast<T>Andreas Kling
This makes it much clearer what this cast actually does: it will VERIFY that the thing we're casting is a T (using is<T>()).
2021-06-24LibCore+AK: Use proper atomics in `Singleton`Daniel Bertalan
2021-06-24AK: Use `__attribute__((name))` for functions everywhereDaniel Bertalan
Clang enforces the ordering that attributes specified with the `[[attr_name]]` syntax must comes before those defines as `__attribute__((attr_name))`. We don't want to deal with that, so we should stick to a single syntax (for functions, at least). This commit favors the latter, as it's used more widely in the code (for declaring more "exotic" options), and changing those would be a larger effort than modifying this single file.
2021-06-24AK: Add factory methods for creating smart pointersDaniel Bertalan
These functions abstract away the need to call the proper new operator ("throwing" or "non-throwing") and manually adopt the resulting raw pointer. Modelled after the existing `NonnullOwnPtr<T> make()` functions, these forward their parameters to the object's constructor. Note: These can't be used in the common "factory method" idiom, as private constructors can't be called from a standalone function. The naming is consistent with AK's and Shell's previous implementation of these: - `make` creates a `NonnullOwnPtr<T>` and aborts if the allocation could not be performed. - `try_make` creates an `OwnPtr<T>`, which may be null if the allocation failed. - `create` creates a `NonnullRefPtr<T>`, and aborts on allocation failure. - `try_create` creates a `RefPtr<T>`, which may be null if the allocation was not successful.
2021-06-24AK+Kernel: Make fallible allocations compiler-agnosticDaniel Bertalan
In standard C++, operators `new` and `new[]` are guaranteed to return a valid (non-null) pointer and throw an exception if the allocation couldn't be performed. Based on this, compilers did not check the returned pointer before attempting to use them for object construction. To avoid this, the allocator operators were changed to be `noexcept` in PR #7026, which made GCC emit the desired null checks. Unfortunately, this is a non-standard feature which meant that Clang would not accept these function definitions, as it did not match its expected declaration. To make compiling using Clang possible, the special "nothrow" versions of `new` are implemented in this commit. These take a tag type of `std::nothrow_t` (used for disambiguating from placement new/etc.), and are allowed by the standard to return null. There is a global variable, `std::nothrow`, declared with this type, which is also exported into the global namespace. To perform fallible allocations, the following syntax should be used: ```cpp auto ptr = new (nothrow) T; ``` As we don't support exceptions in the kernel, the only way of uphold the "throwing" new's guarantee is to abort if the allocation couldn't be performed. Once we have proper OOM handling in the kernel, this should only be used for critical allocations, where we wouldn't be able to recover from allocation failures anyway.
2021-06-24AK: Specialize `Atomic<Integral>` for clang compatibilityDaniel Bertalan
While Clang claims to implement GCC's atomics libcall API, a small incompatibility caused our builds to fail on Clang. Clang requires requires the operands to its fixed-size functions to be integer types, while GCC will take any type with the same size and alignment as the various integer primitives. This was problematic, as atomic `enum class`es would not compile. Furthermore, Clang does not like if only one operand pointer is marked volatile. Because it only affects the standalone atomic functions, that will be fixed in a later commit. As an added benefit, the code is more type-safe, as it won't let us perform arithmetic on non-integer types. Types with overloaded arithmetic types won't cause unexpected behavior anymore. The constructors for the various atomic types can now be used in constant expressions.
2021-06-24AK: Make C++ concepts support mandatory for compilersDaniel Bertalan
The latest GCC and Clang versions both support this, so we can freely use these in our code.
2021-06-24AK: Fix building Ptr32 on x86_64Gunnar Beutner
2021-06-24Kernel: Pull apart CPU.hHendiadyoin1
This does not add any functional changes
2021-06-23AK: Make {min,max,clamp}(T, U) work when U can be implicitly cast to TAli Mohammad Pur
It was really annoying to `static_cast` the arguments to be the same type, so instead of doing that, just convert the second one to the first one, and let the compiler warn about sign differences and truncation.
2021-06-20AK: Reimplement any_of in terms of find_ifLenny Maiorani
Problem: - Now that a generic free-function form of `find_if` is implemented the code in `any_of` is redundant. Solution: - Follow the "don't repeat yourself" mantra and make the code DRY by implementing `any_of` in terms of `find_if`.
2021-06-19AK: Add support for keeping trailing zeros in fixed precision floatsIdan Horowitz
This uses the same syntax as zero padding integers: String::formatted("{:0.5}", 1.234) => "1.23400"
2021-06-19LibCoreDump: Include source locations of inlined functions in backtraceItamar
2021-06-19AK: Add RedBlackTree::find_largest_not_above_iteratorItamar
It's a version of find_largest_not_above that returns an iterator.
2021-06-18AK: Add a way to disable the trimming of whitespace in to_*intsin-ack
This behavior might not always be desirable, and so this patch adds a way to disable it.
2021-06-17AK: Add a :hex-dump mode to AK::FormatAli Mohammad Pur
This will just hexdump the given value. Note that not all formatters respect this, the ones that do are: - (Readonly)Bytes: formatter added in this commit - StringView / char const* - integral types
2021-06-17Meta: Add support for declaring componentsGunnar Beutner
Components are a group of build targets that can be built and installed separately. Whether a component should be built can be configured with CMake arguments: -DBUILD_<NAME>=ON|OFF, where <NAME> is the name of the component (in all caps). Components can be marked as REQUIRED if they're necessary for a minimally functional base system or they can be marked as RECOMMENDED if they're not strictly necessary but are useful for most users. A component can have an optional description which isn't used by the build system but may be useful for a configuration UI. Components specify the TARGETS which should be built when the component is enabled. They can also specify other components which they depend on (with DEPENDS). This also adds the BUILD_EVERYTHING CMake variable which lets the user build all optional components. For now this defaults to ON to make the transition to the components-based build system easier. The list of components is exported as an INI file in the build directory (e.g. Build/i686/components.ini). Fixes #8048.
2021-06-16AK: Add the Utf8View::{contains, trim} helper methodsIdan Horowitz
2021-06-16AK: Remove now unused InlineLinkedList classBrian Gianforcaro
All usages of AK::InlineLinkedList have been converted to AK::IntrusiveList. So it's time to retire our old friend. Note: The empty white space change in AK/CMakeLists.txt is to force CMake to re-glob the header files in the AK directory so incremental build will work when folks git pull this change locally. Otherwise they'll get errors, because CMake will attempt to install a file which no longer exists.
2021-06-16AK+Tests: Add IntrusiveList<T,...>::insert_before(..) methodBrian Gianforcaro
The insert_before method on AK::InlineLinkedList is used, so in order to achieve feature parity, we need to implement it for AK::IntrusiveList as well.
2021-06-16AK: Use IntrusiveList::remove() in the IntrusiveList::prepend() prologBrian Gianforcaro
All other functions use the functionality for removal, use it in the prepend function as well for consistency.
2021-06-15AK: Add support for removing SinglyLinkedList nodes during iterationIdan Horowitz
This commit also fixes the now-broken usage of SinglyLinkedList::remove in the Piano application.
2021-06-15AK: Add a missing `using AK::OrderedHashMap` statementIdan Horowitz
2021-06-15AK: Add Ordering support to HashTable and HashMapHediadyoin1
Adds a IsOrdered flag to Hashtable and HashMap, which allows iteration in insertion order
2021-06-15AK: Add a function that casts an enum to its underlying typeAli Mohammad Pur
This is basically the same thing as `std::to_underlying(Enum)`.
2021-06-13AK: Add FlyString::from_fly_impl()Andreas Kling
This allows you to create a FlyString directly from a known-fly StringImpl instance.
2021-06-13Userland: Allow building SerenityOS with -funsigned-charGunnar Beutner
Some of the code assumed that chars were always signed while that is not the case on ARM hosts. Also, some of the code tried to use EOF (-1) in a way similar to what fgetc() does, however instead of storing the characters in an int variable a char was used. While this seemed to work it also meant that character 0xFF would be incorrectly seen as an end-of-file. Careful reading of fgetc() reveals that fgetc() stores character data in an int where valid characters are in the range of 0-255 and the EOF value is explicitly outside of that range (usually -1).
2021-06-12AK: Add ByteBuffer::append(ReadonlyBytes)Matthew Olsson
2021-06-12AK: Make Ptr32 more transparentHediadyoin1
This adds a transparent dereference operator, aswell as a constant arrow operator Also increaces the verbosity of the code
2021-06-12AK: Rename Vector::append(Vector) => Vector::extend(Vector)Andreas Kling
Let's make it a bit more clear when we're appending the elements from one vector to the end of another vector.