summaryrefslogtreecommitdiff
path: root/AK
AgeCommit message (Collapse)Author
2022-04-05AK: Invalidate UTF-8 encoded code points larger than U+10ffffTimothy Flynn
On oss-fuzz, the LibJS REPL is provided a file encoded with Windows-1252 with the following contents: /ô¡°½/ The REPL assumes the input file is UTF-8. So in Windows-1252, the above is represented as [0x2f 0xf4 0xa1 0xb0 0xbd 0x2f]. The inner 4 bytes are actually a valid UTF-8 encoding if we only look at the most significant bits to parse leading/continuation bytes. However, it decodes to the code point U+121c3d, which is not a valid code point. This commit adds additional validation to ensure the decoded code point itself is also valid.
2022-04-04AK: Make Vector<T>::{first,last}_matching() return Optional<T&>Ali Mohammad Pur
These functions are _very_ misleading, as `first()` and `last()` return references, but `{first,last}_matching()` return copies of the values. This commit makes it so that they now return Optional<T&>, eliminating the copy and the confusion.
2022-04-04AK: Return Optional<T&> from HashMap<..., T>::get()Ali Mohammad Pur
This avoids a useless copy of the value, as most of the users (except one) actually just need a reference to the value.
2022-04-04AK: Return Optional<ConstPeekType> for HashMap::get() constAli Mohammad Pur
While the previous implementation always copied the object, returning a non-const reference to a const object is not valid.
2022-04-04AK: Allow Optional<T&> to existAli Mohammad Pur
This implements Optional<T&> as a T*, whose presence has been missing since the early days of Optional. As a lot of find_foo() APIs return an Optional<T> which imposes a pointless copy on the underlying value, and can sometimes be very misleading, with this change, those APIs can return Optional<T&>.
2022-04-04AK: Add begin_from(V&) APIs to IntrusiveRedBlackTreeIdan Horowitz
This method exploits the fact that the values themselves hold the tree pointers, and as a result this let's us skip the O(logn) traversal down to the matching Node for a Key-Value pair.
2022-04-03AK: Add `StringView::copy_characters_to_buffer()`Tim Schumacher
2022-04-03AK: Add non-const iterator for CircularQueuekleines Filmröllchen
2022-04-03AK: Add generic sincos solution for non-x86 platformsserenityosrocks
2022-04-02AK: Add last() utility function to SpanBen Maxwell
2022-04-02AK+LibHTTP: Ensure plus signs are percent encoded in query stringGeekFiftyFive
Adds a new optional parameter 'reserved_chars' to AK::URL::percent_encode. This new optional parameter allows the caller to specify custom characters to be percent encoded. This is then used to percent encode plus signs by HttpRequest::to_raw_request.
2022-04-02AK: Add vector variants of sqrt and rsqrtHendiadyoin1
2022-04-02AK: Add rsqrt and a SSE specific implementation for sqrtHendiadyoin1
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-31AK: Use bucket states with special bit patterns in HashTablekleines Filmröllchen
This simplifies some of the bucket state handling code, as there's now an easy way of checking the basic category of bucket state.
2022-03-31AK: Rehash HashTable in-place instead of shrinkingkleines Filmröllchen
As seen on TV, HashTable can get "thrashed", i.e. it has a bunch of deleted buckets that count towards the load factor. This means that hash tables which are large enough for their contents need to be resized. This was fixed in 9d8da16 with a workaround that shrinks the HashTable back down in these cases, as after the resize and re-hash the load factor is very low again. However, that's not a good solution. If you insert and remove repeatedly around a size boundary, you might get frequent resizes, which involve frequent re-allocations. The new solution is an in-place rehashing algorithm that I came up with. (Do complain to me, I'm at fault.) Basically, it iterates the buckets and re-hashes the used buckets while marking the deleted slots empty. The issue arises with collisions in the re-hash. For this reason, there are two kinds of used buckets during the re-hashing: the normal "used" buckets, which are old and are treated as free space, and the "re-hashed" buckets, which are new and treated as used space, i.e. they trigger probing. Therefore, the procedure for relocating a bucket's contents is as follows: - Locate the "real" bucket of the contents with the hash. That bucket is the starting point for the target bucket, and the current (old) bucket is the bucket we want to move. - While we still need to move the bucket: - If we're the target, something strange happened last iteration or we just re-hashed to the same location. We're done. - If the target is empty or deleted, just move the bucket. We're done. - If the target is a re-hashed full bucket, we probe by double-hashing our hash as usual. Henceforth, we move our target for the next iteration. - If the target is an old full bucket, we swap the target and to-move buckets. Therefore, the bucket to move is a the correct location and the former target, which still needs to find a new place, is now in the bucket to move. So we can just continue with the loop; the target is re-obtained from the bucket to move. This happens for each and every bucket, though some buckets are "coincidentally" moved before their point of iteration is reached. Either way, this guarantees full in-place movement (even without stack storage) and therefore space complexity of O(1). Time complexity is amortized O(2n) asssuming a good hashing function. This leads to a performance improvement of ~30% on the benchmark introduced with the last commit. Co-authored-by: Hendiadyoin1 <leon.a@serenityos.org>
2022-03-31AK: Merge HashTable bucket state into one enumkleines Filmröllchen
The hash table buckets had three different state booleans that are in fact exclusive. In preparation for further states, this commit consolidates them into one enum. This has the added benefit on not relying on the compiler's boolean packing anymore; we definitely now only need one byte for the bucket state.
2022-03-30AK: Allow printing wide characters using %ls modifiersafarp
2022-03-28LibXML: Add a fairly basic XML parserAli Mohammad Pur
Currently this can parse XML and resolve external resources/references, and read a DTD (but not apply or verify its rules). That's good enough for _most_ XHTML documents as the HTML 5 spec enforces its own rules about document well-formedness, and does not make use of XML DTDs (aside from a list of predefined entities). An accompanying `xml` utility is provided that can read and dump XML documents, and can also run the XML conformance test suite.
2022-03-28AK: Add a 'OneOf' conceptAli Mohammad Pur
Similar to 'SameAs', but for multiple types.
2022-03-28AK: Display SourceLocation function name in colorAli Mohammad Pur
It's much easier to spot the function name (which is what you often expect) like this.
2022-03-28AK: Add a 'is_not_any_of' similar to 'is_any_of' to GenericLexerAli Mohammad Pur
It's often useful to have the negated version, so instead of making a local lambda for it, let's just add the negated form too.
2022-03-28AK: Make Vector capable of holding forward-declared typesAli Mohammad Pur
This is pretty useful for making trees.
2022-03-28AK: Add `appendln` helper to SourceGeneratorHendiadyoin1
2022-03-28AK: Explicitly move `value` String in SourceGenerator::setHendiadyoin1
2022-03-28AK: Make SourceGenerator move constructibleHendiadyoin1
This makes us able to return one from a function
2022-03-27AK: Add an ArbitrarySizedEnum templateLinus Groh
This is an enum-like type that works with arbitrary sized storage > u64, which is the limit for a regular enum class - which limits it to 64 members when needing bit field behavior. Co-authored-by: Ali Mohammad Pur <mpfard@serenityos.org>
2022-03-27AK: Add non-const DistinctNumeric::value() getterLinus Groh
2022-03-27AK: Remove unused String.h include from UFixedBigInt.hLinus Groh
This makes it usable in the Kernel. :^)
2022-03-24LibWeb: Rename PARSER_DEBUG => HTML_PARSER_DEBUGIdan Horowitz
Since this macro was created we gained a couple more parsers in the system :^)
2022-03-21AK: Add a case insensitive of is_one_of to String[View]Hendiadyoin1
2022-03-19AK: Fix typo in warnln_if()Sam Atkins
2022-03-18AK+Tests: Fix StringUtils::contains() being confused by repeating textSam Atkins
Previously, case-insensitively searching the haystack "Go Go Back" for the needle "Go Back" would return false: 1. Match the first three characters. "Go ". 2. Notice that 'G' and 'B' don't match. 3. Skip ahead 3 characters, plus 1 for the outer for-loop. 4. Now, the haystack is effectively "o Back", so the match fails. Reducing the skip by 1 fixes this issue. I'm not 100% convinced this fixes all cases, but I haven't been able to find any cases where it doesn't work now. :^)
2022-03-18Everywhere: Deduplicate day/month name constantsLenny Maiorani
Day and month name constants are defined in numerous places. This pulls them together into a single place and eliminates the duplication. It also ensures they are `constexpr`.
2022-03-18AK: Mark the StringView user-defined literal as constevalTimothy Flynn
Even though the StringView(char*, size_t) constructor only runs its overflow check when evaluated in a runtime context, the code generated here could prevent the compiler from optimizing invocations from the StringView user-defined literal (verified on Compiler Explorer). This changes the user-defined literal declaration to be consteval to ensure it is evaluated at compile time.
2022-03-18AK: Add const variant of Vector::in_reverse()Andreas Kling
2022-03-17Everywhere: Switch from EnableIf to requiresLenny Maiorani
C++20 provides the `requires` clause which simplifies the ability to limit overload resolution. Prefer it over `EnableIf` With all uses of `EnableIf` being removed, also remove the implementation so future devs are not tempted.
2022-03-18AK: Add constant time equality and zero check to UFixedBigIntMichiel Visser
2022-03-18AK: UFixedBigInt add efficient multiplication with full resultMichiel Visser
2022-03-16AK: Fix implicit and narrowing conversions in Base64Lenny Maiorani
2022-03-16AK: Make static constexpr variables to avoid stack copy in Base64Lenny Maiorani
Alphabet and lookup table are created and copied to the stack on each call. Create them and store them in static memory.
2022-03-15AK+Kernel: Avoid double memory clearing of HashTable bucketsDaniel Bertalan
Since the allocated memory is going to be zeroed immediately anyway, let's avoid redundantly scrubbing it with MALLOC_SCRUB_BYTE just before that. The latest versions of gcc and Clang can automatically do this malloc + memset -> calloc optimization, but I've seen a couple of places where it failed to be done. This commit also adds a naive kcalloc function to the kernel that doesn't (yet) eliminate the redundancy like the userland does.
2022-03-15AK+Everywhere: Add sincos and use it in some placesHendiadyoin1
Calculating sin and cos at once is quite a bit cheaper than calculating them individually. x87 has even a dedicated instruction for it: `fsincos`.
2022-03-14AK: Allow creating a Vector from any Span of the same underlying typeTimothy Flynn
This allows, for example, to create a Vector from a subset of another Vector.
2022-03-13AK: Add naive implementations of AK::timing_safe_compareBrian Gianforcaro
For security critical code we need to have some way of performing constant time buffer comparisons.
2022-03-12AK: Properly parse unimplemented format length specifiersTim Schumacher
This keeps us from stopping early and not rendering the argument at all.
2022-03-10AK: Remove unused String[256] from JsonParserSam Atkins
This shrinks the JsonParser class from 2072 bytes to 24. :^)
2022-03-09AK: Print a better error message when missing a SourceGenerator keySam Atkins
Previously, if you forgot to set a key on a SourceGenerator, you would get this less-than-helpful error message: > Generate_CSS_MediaFeatureID_cpp: /home/sam/serenity/Meta/Lagom/../../AK/Optional.h:174: T AK::Optional<T>::release_value() [with T = AK::String]: Assertion `m_has_value' failed. Now, it instead looks like this: > No key named `name:titlecase` set on SourceGenerator Generate_CSS_MediaFeatureID_cpp: /home/sam/serenity/Meta/Lagom/../../AK/SourceGenerator.h:44: AK::String AK::SourceGenerator::get(AK::StringView) const: Assertion `false' failed.
2022-03-09AK: Add reverse iterator as memberFederico Guerinoni
2022-03-09AK: Implement wrapper for reverse range for loopFederico Guerinoni
Now it is possible to use range for loop in reverse mode for a container. ``` for (auto item : in_reverse(vector)) ```