summaryrefslogtreecommitdiff
path: root/AK
AgeCommit message (Collapse)Author
2020-12-12AK::URL: Fix setting the port number in the case it was the last element of ↵xspager
the URL
2020-12-10AK: Add String::substring(start)Andreas Kling
This is a convenience API when you just want the rest of the string starting at some index. We already had substring_view() in the same flavor, so this is a complement to that.
2020-12-10AK: Ensure dual_pivot_quick_sort does not copy the pivotsAnotherTest
Also add a test that would fail to compile if quick_sort tries to copy anything :P
2020-12-09AK: Fix offset calculation error in DuplexMemoryStream::write.asynts
2020-12-09AK: Fix unsigned integer underflow in DuplexMemoryStream::write.asynts
2020-12-09AK: Add String::substring_view(size_t).asynts
2020-12-08AK: Fix reading across chunks in DuplexMemoryStreamAnotherTest
2020-12-08AK: Implement DuplexMemoryStream::offset_of() in terms of memmem()AnotherTest
This fixes the FIXME about missing matches that go across chunk boundaries.
2020-12-08AK: Implement memmem() for iterator haystacksAnotherTest
This uses the KMP algorithm to implement the search. Also replaces the slow route of the normal memmem() with KMP, which should be fairly faster (O(n + m) as opposed to O(n * m)) :^)
2020-12-08AK: Forward declare Nonnull{Own,Ref}PtrVectorAnotherTest
2020-12-08AK: Add header for SIMD vectorized typesSahan Fernando
2020-12-06AK: Make Formatter<StringView> not choke on Mode::CharacterLinus Groh
Formatter<char> internally uses Formatter<StringView> when in Mode::Character, but that would only accept Mode::{Default,String} and ASSERT_NOT_REACHED() otherwise, causing String::formatted("{:c}", 'a') to crash
2020-12-06AK: Add test for the will_be_destroyed and one_ref_left magic functionsAndrew Kaster
Fixes a regression introduced by 5c1b3ce. The commit description there asserts that the changes allow calling will_be_destroyed and one_ref_left, which are not required to be const qualified. The implementation in fact does require the methods to be const qualified, because we forgot to add the const_cast inside the decltypes :^)
2020-12-05AK: Pull Is{Integral,FloatingPoint} into the global namespaceLinus Groh
2020-12-02AK: Add insert_before/insert_after to InlineLinkedListTom
2020-11-30AK: Fix logic error in urldecode() percent-decodingLinus Groh
We also need to append the raw consumed value if *either* of the two characters after the % isn't a hex digit, not only if *both* aren't. Fixes #4257.
2020-11-29AK: Export ShouldChomp::NoChomp tooAnotherTest
It's much more elegant to say 'should_chomp ? Chomp : NoChomp' than to say 'if (should_chomp) ...(..., Chomp) else ...(...)'.
2020-11-29AK: Add missing GenericTraits<u8>devashish
This enables us to use keys of type u8 in HashMaps.
2020-11-27Lagom: Various fixes to make Lagom run on OSS-Fuzz (#4176)DavidKorczynski
2020-11-25AK: Always inline RefPtr::operator bool() and RefPtr::is_null()Andreas Kling
2020-11-25AK: Don't return empty StringImpl from create() when char* starts with \0Linus Groh
When creating a StringImpl for a C string that starts with a null-byte, we would ignore the explicitly given length and return the empty StringImpl - presumably to check for "\0", but this leads to false positives ("\0foo") so let's only care about the length.
2020-11-24AK: Add some inline capacity to StringBuilderAndreas Kling
This patch adds a 128-byte inline buffer that we use before switching to using a dynamically growing ByteBuffer. This allows us to avoid heap allocations in many cases, and totally incidentally also speeds up @nico's favorite test, "disasm /bin/id" more than 2x. :^)
2020-11-24AK: Add IntrusiveList::take_last()Andreas Kling
2020-11-23LibIPC: Prepend each message with its sizeSergey Bugaev
This makes it much simpler to determine when we've read a complete message, and will make it possible to integrate recvfd() in the future commit.
2020-11-23AK: Add Vector::prepend() overload for multiple itemsSergey Bugaev
Much like with Vector::append(), you may want to append multiple items in one go. It's actually more important to do this for prepending, because you don't want to copy the rest of items further each time.
2020-11-23AK: Use ALWAYS_INLINE all over NonnullPtrVectorAndreas Kling
I saw NonnullOwnPtrVector::at() in a profile and that was silly, as we should definitely be inlining it.
2020-11-22AK: Add first_matching and last_matching to VectorLuke
first_matching returns the first item in the vector that matches the given condition. last_matching returns the last item in the vector that matches the given condition.
2020-11-22AK: Fix base64 decoding '/'BenJilks
When creating the lookup table, it wouldn't add the last character
2020-11-22AK: Cleanup missing includes and #ifdef evaluationLenny Maiorani
Problem: - Several files have missing includes. This results in complaints from `clang-tidy`. - `#ifdef` is followed by `#elif <value>` which evaluates to `0`. Solution: - Add missing includes. - Change to `#elif defined(<value>)`.
2020-11-22NeverDestroyed: Add testsLenny Maiorani
Problem: - It is difficult to refactor because there are no tests to bind the functionality. - Arguments are not forwarded correctly to the constructor. Solution: - Add tests. - Change constructor to take forwarding references.
2020-11-21MACAddress: Use all_of to implement is_zeroLenny Maiorani
Problem: - `is_zero()` is implemented by checking each value in the array by hand. This is error-prone and less expressive than using an algorithm. Solution: - Implement `is_zero()` in terms of `all_of`.
2020-11-21AK: Implement generic all_of algorithmLenny Maiorani
Problem: - Raw loops are often written to validate that all values in a container meet a predicate, but raw loops are not as expressive as functions implementing well-named algorithms and are error-prone. Solution: - Implement a very generic form of `all_of`.
2020-11-20MACAddress: AK::Array as member variable instead of C-arrayLenny Maiorani
Problem: - C-style arrays do not automatically provide bounds checking and are less type safe overall. - `__builtin_memcmp` is not a constant expression in the current gcc. Solution: - Change private m_data to be AK::Array. - Eliminate constructor from C-style array. - Change users of the C-style array constructor to use the default constructor. - Change `operator==()` to be a hand-written comparison loop and let the optimizer figure out to use `memcmp`.
2020-11-19MACAddress: constexpr supportLenny Maiorani
Problem: - `MACAddress` class is not usable in a compile-time context. - `__builtin_memcpy` is not constexpr in gcc. Solution: - Decorate functions with `constexpr` keyword. - Use default constructors and destructors. - Change `__builtin_memcpy` to a hand-written `for` loop and let the compiler's optimizer take care of it. - Add tests to ensure compile-time capabilities.
2020-11-17AK: Fix OOB access in DuplexMemoryStream::offset_of()AnotherTest
This fixes an OOB access when the last read/written chunk is empty (as we _just_ started on a new chunk). Also adds a test case to TestMemoryStream. Found via human fuzzing in the shell: ```sh for $(cat /dev/urandom) { clear match $it { ?* as (x) { echo $x sleep 1 } } } ``` would assert at some point.
2020-11-17AK: Trim whitespace in StringUtils::convert_to_{int,uint,uint_from_hex}()Linus Groh
Personally I found this unintuitive at first, but it is in line with strtol(), Python's int() or JavaScript's parseInt(), so I guess it makes sense. Fixes #4097.
2020-11-17MACAddress: Unit testing for basic functionalityLenny Maiorani
Problem: - There are no unit tests for `MACAddress` class. This makes it difficult to refactor and ensure the same behavior. - `m_data` private member variable is uninitialized leading to undefined behavior of `is_zero()`. Solution: - Add unit tests to cover basic functionality. - Initialize `m_data`.
2020-11-16Vector: C++20 equality operatorsLenny Maiorani
Problem: - C++20 changes the way equality operators are generated. This results in overload ambiguity as reported by clang. Solution: - Remove `AK::Vector::operator!=` because it will be automatically generated in terms of `AK::Vector::operator==`. - Change `AK::Vector::operator==` to be a function template so that overload resolution is not confused about `a == b` vs `b == a`. - Add tests to ensure the behavior works. Notes: - There is more info available at https://brevzin.github.io/c++/2019/07/28/comparisons-cpp20/ for deeper discussion about overload resolution, operator rewriting, and generated functions.
2020-11-15Everywhere: Add missing <AK/ByteBuffer.h> includesAndreas Kling
All of these files were getting ByteBuffer.h from someone else and then using it. Let's include it explicitly.
2020-11-14AK: Mark SimpleIterator::operator*() as ALWAYS_INLINEAndreas Kling
This gives the compiler enough information to optimize index validation when using range-for to iterate over a Vector, drastically reducing the cost of such loops.
2020-11-14AK: Fix StringUtils::contains() case insensitive searchLinus Groh
It would incorrectly return false if needle was at the end the string.
2020-11-13AK: Fix inverted condition in unsigned LEB128 decodeAndreas Kling
2020-11-12AK: Prefer using instead of typedefLenny Maiorani
Problem: - `typedef` is a keyword which comes from C and carries with it old syntax that is hard to read. - Creating type aliases with the `using` keyword allows for easier future maintenance because it supports template syntax. - There is inconsistent use of `typedef` vs `using`. Solution: - Use `clang-tidy`'s checker called `modernize-use-using` to update the syntax to use the newer syntax. - Remove unused functions to make `clang-tidy` happy. - This results in consistency within the codebase.
2020-11-11RefPtrTraits: struct/class mismatch in forward declarationLenny Maiorani
Problem: - Building with clang is broken because of the `struct` vs `class` mismatch between the definition and declaration. Solution: - Change `class` to `struct` in the forward declaration.
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