summaryrefslogtreecommitdiff
path: root/AK
AgeCommit message (Collapse)Author
2020-11-11IPv4Address: constexpr supportLenny Maiorani
Problem: - IPv4Address class cannot be used in a compile-time context. - A union is used by initializing one of the members and reading the non-active member. This is undefined behavior and not permitted in a `constexpr` context. Solution: - Eliminate undefined behavior by changing to a simple `u32` for storage instead of the union and performing mask/shift calculations for obtaining the individual octets. - Decorate functions with `constexpr` where possible. Currently string formatting and optionals are not `constexpr`-capable so functions using those are left out. - Modify tests to validate functionality in a `constexpr` context in addition to the run-time tests already being run. This ensures that functionality is the same in both contexts.
2020-11-10AK: Make RefPtr, NonnullRefPtr, WeakPtr thread safeTom
This makes most operations thread safe, especially so that they can safely be used in the Kernel. This includes obtaining a strong reference from a weak reference, which now requires an explicit call to WeakPtr::strong_ref(). Another major change is that Weakable::make_weak_ref() may require the explicit target type. Previously we used reinterpret_cast in WeakPtr, assuming that it can be properly converted. But WeakPtr does not necessarily have the knowledge to be able to do this. Instead, we now ask the class itself to deliver a WeakPtr to the type that we want. Also, WeakLink is no longer specific to a target type. The reason for this is that we want to be able to safely convert e.g. WeakPtr<T> to WeakPtr<U>, and before this we just reinterpret_cast the internal WeakLink<T> to WeakLink<U>, which is a bold assumption that it would actually produce the correct code. Instead, WeakLink now operates on just a raw pointer and we only make those constructors/operators available if we can verify that it can be safely cast. In order to guarantee thread safety, we now use the least significant bit in the pointer for locking purposes. This also means that only properly aligned pointers can be used.
2020-11-10AK: Add RefPtrTraits to allow implementing custom null pointersTom
This adds the ability to implement custom null states that allow storing state in null pointers.
2020-11-10IPv4Address: Unit testsLenny Maiorani
Problem: - There is no direct unit testing of the IPv4Address functionality which makes refactoring difficult. Solution: - Add unit tests to cover the current functionality of IPv4Address. This will allow future refactorings with confidence.
2020-11-09AK: Add formatters for floating point numbers.asynts
2020-11-09AK: Rename new_out to out and new_warn to warn.asynts
2020-11-09AK: Remove out() and warn().asynts
2020-11-08AK: Use reference algorithms for LEB128 parsingAndreas Kling
This fixes a bug in signed LEB128 parsing (sign extension stage) which would sometimes cause debug info to look very strange.
2020-11-08LibJS+AK: Move cross-platform stack bounds code from JS::Heap to AK::StackInfoLinus Groh
This will be useful for other things than the Heap, maybe even outside of LibJS.
2020-11-07AK: Remove duplicate begin()/end() methodsNico Weber
begin()/end() returning a ConstItertor already exist further up in this file. Nothing uses these redundant versions, and they are not callable.
2020-11-05AK: printf was not accounting for plus sign with "%+d"Andreas Kling
We have to include the plus sign in the number of characters written, otherwise sprintf() will put the null terminator too early.
2020-11-05AK: Always include <new> from compiler before our operators newAndreas Kling
We had competing inline definitions of the placement operators new. Avoid this by having <AK/kmalloc.h> pull in <new> from the compiler and always using their definitions instead. I feel like there must be an elegant solution to this whole situation with the operators, but I'm not sure what it is.
2020-11-04AK::URL: Check if URL requires a port set to be considered a valid URLBrendan Coles
`AK::URL` will now check if the URL requires a port to be set using `AK::URL.protocol_requires_port(protocol)`. If the URL does not specify a port, and no default port for the URL protocol is found with `AK::URL.default_port_for_protocol(protocol)`, the URL is considered to be invalid.
2020-11-03AK: Really disallow making OwnPtrs from refcounted typesAnotherTest
This looks at three things: - if the type has a typedef `AllowOwnPtr', respect that - if not, disallow construction if both of `ref()' and `unref()' are present. Note that in the second case, if a type only defines `ref()' or only defines `unref()', an OwnPtr can be created, as a RefPtr of that type would be ill-formed. Also marks a `Performance' to explicitly allow OwnPtrs.
2020-11-02AK+Kernel: Escape JSON keys & valuesAndreas Kling
Grab the escaping logic from JSON string value serialization and use it for serializing all keys and values. Fixes #3917.
2020-10-29AK: Make String::matches() capable of reporting match positions tooAnotherTest
Also, rewrite StringUtils::match(), because the old implementation was fairly broken, e.g. "acdcxb" would *not* match "a*?b".
2020-10-29AK: Add a `is_one_of()' to StringViewAnotherTest
This copies the similar API from String.
2020-10-29CMake: Use CONFIGURE_DEPENDS in existing globs.asynts
2020-10-29AK: Add GenericLexer::retreat()Linus Groh
This allows going back one character at a time, and then re-consume previously consumed chars. The code I need this for looks something like this: ASSERT(lexer.consume_specific('\\')); if (lexer.next_is("foo")) ... lexer.retreat(); lexer.consume_escaped_character(); // This expects lexer.peek() == '\\'
2020-10-25AK: Deprecate warn().asynts
2020-10-25AK: Eradicate calls to warn().asynts
2020-10-25AK: Remove a really slow unit test.asynts
2020-10-24AK: Add [[deprecated]] to out().asynts
2020-10-24AK: Introduce SourceGenerator::fork().asynts
Previously, I abused the copy constructor, this is a lot better.
2020-10-22AK: Add `GenericLexer::consume_escaped_character()'AnotherTest
...and use it in `consume_and_unescape_string()'.
2020-10-22AK: Enhance String::contains to allow case-insensitive searchesTom
2020-10-22AK: Make Utf8View and Utf32View more consistentTom
This enables use of these classes in templated code.
2020-10-21TestArray: constexpr_sum using spanLenny Maiorani
Problem: - `constexpr_sum` is implemented using `Array` which means the function needs to be a function template so that the size can be deduced. Solution: - Change the `Array` function argument to a `Span` since `Span` now is `constexpr`.
2020-10-21HashFunctions: constexpr capabilityLenny Maiorani
Problem: - Hash functions can be `constexpr`, but are not. Solution: - Change `inline` keyword to `constexpr`. - Add `static_assert` tests to ensure the hash functions work in a `constexpr` context.
2020-10-21TestHashFunctions: Tests to bind hash functionalityLenny Maiorani
Problem: - The hash functions have no associated tests, so there is nothing binding their behavior. Solution: - Bind the hash function behavior by adding tests. - Use the existing behavior as "correct".
2020-10-20Everywhere: Redundant inline specifier on constexpr functions (#3807)Lenny Maiorani
Problem: - `constexpr` functions are decorated with the `inline` specifier keyword. This is redundant because `constexpr` functions are implicitly `inline`. - [dcl.constexpr], §7.1.5/2 in the C++11 standard): "constexpr functions and constexpr constructors are implicitly inline (7.1.2)". Solution: - Remove the redundant `inline` keyword.
2020-10-20Checked: constexpr supportLenny Maiorani
Problem: - `Checked` is not `constexpr`-aware. Solution: - Decorate member functions with `constexpr` keyword. - Add tests to ensure the functionality where possible.
2020-10-20Checked: Use default compiler-generated functionsLenny Maiorani
Problem: - Compiler-generated functions are being defined which results in extra code to maintain. Solution: - Switch to compiler-generated default functions for default construction, copy assignment, move assignment, copy construction and move construction.
2020-10-20Build: Modify various parts to allow the build to succeed on FreeBSDLaurent Cimon
2020-10-18AK: Reduce memory writes in HashTable destructorDano Perniš
2020-10-18AK: Implement HashTable assignment in terms of swapDano Perniš
2020-10-18AK: Provide swap() for HashTableDano Perniš
2020-10-17CircularQueue: Ensure constructor does not construct any valuesLenny Maiorani
Problem: - There is no test which guarantees the CircularQueue does not construct any objects of the value type. The goal is to have uninitialized memory which can be used. Solution: - Add a test requiring that the constructor of the value type is never called.
2020-10-17AK: Add formatters for NonnullOwnPtr and WeakPtr.asynts
2020-10-17AK+Format: Add outln(FILE*, ...) overload.asynts
This commit also removes a few functions like raw_out and vwarn. If we want to write raw output, we can do this as follows: out("{}", "Hello, World!"); The vout stuff isn't really public API anyways, so no need for another vwarn.
2020-10-17BinarySearch: constexpr supportLenny Maiorani
Problem: - It is not possible to perform a binary search at compile-time because `binary_search` is not `constexpr`-aware. Solution: - Add `constexpr` support.
2020-10-17ntpquery: Don't leak local time, and check origin time in replyNico Weber
This implements the transmit time suggestion in (abandoned?) draft-ietf-ntp-data-minimization. (The other suggestions were already implemented as far as I can tell.)
2020-10-16Span: constexpr supportLenny Maiorani
Problem: - `Span` is not `constexpr` aware. Solution: - Add `constexpr` support for all parts that do not require `reinterpret_cast`. - Modify tests which use the `constexpr` functions.
2020-10-16AK: Tune HashTable load factorAndreas Kling
Double the capacity when used+deleted buckets crosses 60% of capacity. This appears to be a sweet spot for performance based on some ad-hoc testing with test-js. :^)
2020-10-16AK: Add some more checks to the HashMap testAndreas Kling
2020-10-15AK: Redesign HashTable to use closed hashingAndreas Kling
Instead of each hash bucket being a SinglyLinkedList, switch to using closed hashing (open addressing). Buckets are chained together via double hashing (hashing the hash until we find an unused bucket.) This greatly reduces malloc traffic, since each added element no longer allocates a new linked list node. Appears performance neutral on test-js. Can definitely be tuned and could use proper management of load factor, etc.
2020-10-15AK: Improve HashMap tests a little bitAndreas Kling
2020-10-14AK: Don't forward declare abort.asynts
There is no portable way to forward declare abort because the libc implementations disagree on the signature. Originally, I added a __portable_abort function with a "portable" signature which just called abort. But I really don't like it and just including <stdlib.h> is simpler. Note that the headers we include in <AK/TestSuite.h> are no longer commutative now, we have to include <stdlib.h> before anything else.
2020-10-13Base64: Pre-allocate size of input and outputLenny Maiorani
Problem: - Output of decode and encode grow as the decode and encode happen. This is inefficient because a large size will require many reallocations. - `const` qualifiers are missing on variables which are not intended to change. Solution: - Since the size of the decoded or encoded message is known prior to starting, calculate the size and set the output to that size immediately. All appends will not incur the reallocation overhead. - Add `const` qualifiers to show intent.
2020-10-13Use new format functions in remaining DevTools. (#3755)Paul Scharnofske
* AK: Add formatter for JsonValue. * Inspector: Use new format functions. * Profiler: Use new format functions. * UserspaceEmulator: Use new format functions.