summaryrefslogtreecommitdiff
path: root/AK
AgeCommit message (Collapse)Author
2023-04-13AK+Tests: Add Vector::find_first_index_if()Sam Atkins
2023-04-12Everywhere: Fix a few typosNico Weber
Some even user-visible!
2023-04-12AK: Make grepping for "lerp" find mix()Nico Weber
2023-04-12AK: Remove the Endian bytes accessorTim Schumacher
This is a remnant from when we didn't have a `read_value` and `write_value` implementation for `AK::Endian` and instead used the generic functions for reading a span of bytes. Now that we have a more ergonomic alternative, remove the helper that is no longer needed.
2023-04-12AK: Don't store parts of URLs percent decodedMacDue
As noted in serval comments doing this goes against the WC3 spec, and breaks parsing then re-serializing URLs that contain percent encoded data, that was not encoded using the same character set as the serializer. For example, previously if you had a URL like: https:://foo.com/what%2F%2F (the path is what + '//' percent encoded) Creating URL("https:://foo.com/what%2F%2F").serialize() would return: https://foo.com/what// Which is incorrect and not the same as the URL we passed. This is because the re-serializing uses the PercentEncodeSet::Path which does not include '/'. Only doing the percent encoding in the setters fixes this, which is required to navigate to Google Street View (which includes a percent encoded URL in its URL). Seems to fix #13477 too
2023-04-11AK+Everywhere: Use Optional for URLParser::parse's base_url parameternetworkException
2023-04-11AK: Allow human_readable_size_long to use a thousands separatorTim Ledbetter
2023-04-11AK: Add option to the string formatter to use a digit separatorTim Ledbetter
`vformat()` can now accept format specifiers of the form {:'[numeric-type]}. This will output a number with a comma separator every 3 digits. For example: `dbgln("{:'d}", 9999999);` will output 9,999,999. Binary, octal and hexadecimal numbers can also use this feature, for example: `dbgln("{:'x}", 0xffffffff);` will output ff,fff,fff.
2023-04-09LibCore: Fix corner case for files without newlinesRodrigo Tobar
When BufferedFile.can_read_line() was invoked on files with no newlines, t incorrectly returned a false result for this single line that, even though doesn't finish with a newline character, is still a line. Since this method is usually used in tandem with read_line(), users would miss reading this line (and hence all the file contents). This commit fixes this corner case by adding another check after a negative result from finding a newline character. This new check does the same as the check that is done *before* looking for newlines, which takes care of this problem, but only works for files that have at least one newline (hence the buffer has already been filled). A new unit test has been added that shows the use case. Without the changes in this commit the test fails, which is a testament that this commit really fixes the underlying issue.
2023-04-08AK: Bake CLion IDE check into AK_COMPILER_CLANGAndreas Kling
For whatever reason, when CLion does its code indexing thing, it doesn't define __clang__ despite using Clang. This causes it to run into various problems that we've solved by checking for Clang. Since CLion does define __CLION_IDE__ (or sometimes __CLION_IDE_, no idea why but I have seen this issue locally), let's make that part of the AK_COMPILER_CLANG check. This makes CLion stop highlighting various things as errors.
2023-04-07AK: Allow specifying a minimum value for IDs returned by IDAllocatorTimothy Flynn
2023-04-06AK: Add FlyString::is_one_of for variadic string comparisonKenneth Myhra
2023-04-06AK: Add to_string() for IPv4Addressstelar7
2023-04-05AK+LibCompress: Break when seekback copying to a full CircularBufferTim Schumacher
Otherwise, we just end up infinitely looping while waiting for more space in the destination.
2023-04-05AK: Report copied bytes when seekback copying from CircularBufferTim Schumacher
Otherwise, we have no way of determining whether our copy was truncated by accident.
2023-04-05AK: Properly limit the internal seekback span for CircularBufferTim Schumacher
I was originally thinking in the wrong direction when adding this limit, we can at most read from the buffer until we reach the current write head. Since that write head is the reference point for the distance, we need to limit ourselves to that instead of the seekback limit (which is the maximum of how far back the distance can be).
2023-04-03AK+Everywhere: Change AK::fill_with_random to accept a Bytes objectTimothy Flynn
Rather than the very C-like API we currently have, accepting a void* and a length, let's take a Bytes object instead. In almost all existing cases, the compiler figures out the length.
2023-04-03AK: Add templated Span<u8> and Span<u8 const> constructors for C-arraysTimothy Flynn
This helper constructor exists on the unspecialized Span<T> class also, and is convenient for e.g. creating Bytes from: u8 buffer[64]; Bytes bytes { buffer };
2023-04-03AK: Prevent passing lengths greater than 256 to getentropy()Timothy Flynn
From the getentropy() man page, "The maximum permitted value for the length argument is 256". Several of our tests were passing lengths of several thousand bytes, causing getentropy() to fail with EIO, which we were completely ignoring. This caused these tests to only test long sequences of 0x00. We now loop over the provided buffer to fill it 256 bytes at a time. If getentropy() fails for any reason, we fall back to the default method of filling it with one random byte at a time.
2023-04-02AK: Increase LittleEndianOutputBitStream's buffer size and remove loopsTimothy Flynn
This is very similar to the LittleEndianInputBitStream bit buffer change from 8e834d4bb2f8a217013142658fe7203c5a5c3170. We currently buffer one byte of data for the underlying stream. And when we put bits onto that buffer, we do so 1 bit at a time. This replaces the u8 buffer with a u64. And instead of looping at all, we perform bitwise operations to write the desired number of bits. Using the "enwik8" file as a test (100MB uncompressed, commonly used in benchmarks: https://www.mattmahoney.net/dc/enwik8.zip), compression time decreases from: 13.62s to 10.9s on Serenity (cold) 13.62s to 9.22s on Serenity (warm) 2.93s to 2.32s on Linux One caveat is that this requires explicitly flushing any leftover bits when the caller is done with the stream. The byte buffer implementation implicitly flushed its data every time the buffer was byte-aligned, as doing so would always fill the byte. This is no longer the case. But for now, this should be fine as the one user of this class, DEFLATE, already has a "flush everything now that we're done" finalizer.
2023-03-31AK+LibCompress: Remove the Deflate back-reference intermediate bufferTimothy Flynn
Instead of reading bytes from the output stream into a buffer, just to immediately write them back out, we can skip the middle-man and copy the bytes directly into the output buffer.
2023-03-30AK: Remove BitStream workaround for now-resolved BufferedStream behaviorTimothy Flynn
The issue was that the buffer would only be filled if it was empty.
2023-03-30AK: Refill a BufferedStream when it has less than the requested sizeTimothy Flynn
We currently only fill a buffer when it is empty. So if it has 1 byte and 16 KB was requested, only that 1 byte would be returned. Instead, attempt to refill the buffer when it's size is less than the requested size.
2023-03-30AK: Remove arbitrary 1 KB limit when filling a BufferedStream's bufferTimothy Flynn
When reading, we currently only fill a BufferedStream's buffer when it is empty, and only with 1 KB of data. This means that while the buffer defaults to a size of 16 KB, at least 15 KB is always unused.
2023-03-29AK: Fix Clang 16 UBSan issue with zero-length `Array`Daniel Bertalan
The current implementation of `Array<T, 0>` has a zero-length C array as its storage type. While this is accepted as a GNU extension, when compiling with Clang 16, an UBSan error is raised every time an object is accessed whose only field is a zero-length array. This is likely a bug in Clang 16's implementation of UBSan, which has been reported here: https://github.com/llvm/llvm-project/issues/61775
2023-03-29AK: Fix build with Xcode 14.2's clangNico Weber
Else: AK/BitStream.h:218:24: error: inline function '...::lsb_mask<unsigned char>' is not defined [-Werror,-Wundefined-inline] static constexpr T lsb_mask(T bits) ^
2023-03-29AK: Increase LittleEndianInputBitStream's buffer size and remove loopsTimothy Flynn
We current buffer one byte of data from the underlying stream. And when we pull bits off that buffer, we do so 1 or 8 bits at a time (depending on whether the buffer is byte aligned). The 1-bit-at-a-time loop is by far the most common during e.g. GZIP decompression. This replaces the u8 buffer with a u64. And instead of looping at all, we perform bitwise operations to extract the desired number of bits. Using the "enwik8" file as a test (100MB uncompressed, commonly used in benchmarks: https://www.mattmahoney.net/dc/enwik8.zip), decompression time decreases from: 242s to 35s on Serenity 11.125s to 3.527s on Linux Note that BigEndianInputBitStream can also use the same techniques, and some of the methods here may make sense to live in an endianness- agnostic base class. The focus is GZIP right now though, which only uses the little endian stream.
2023-03-29AK: Add NumericLimits::digits to return the number of digits in a typeTimothy Flynn
Analogous to std::numeric_limits<T>::digits.
2023-03-28AK: Add DeprecatedString::from_utf8(StringView)Ali Mohammad Pur
This mirrors String::from_utf8(StringView). Jakt will use this to construct strings instead of just assuming the allocation will succeed, lowering the API difference between Jakt::String and AK::String by one API :^)
2023-03-22AK: Expose the current position of a Utf8CodePointIterator as a pointerSam Atkins
2023-03-21AK: Expose the seekback limit of CircularBufferTim Schumacher
2023-03-21AK: Add a Stream wrapper that counts read bytesTim Schumacher
2023-03-21AK: Move ConstrainedStream from LibWasm and limit discardingTim Schumacher
2023-03-18AK: Export FlyString from the forwarding headerTimothy Flynn
2023-03-17LibGfx/OpenType: Add some initial support for GPOS glyph positioningAndreas Kling
This patch parses enough of GPOS tables to be able to support the kerning information embedded in Inter. Since that specific font only applies positioning offsets to the first glyph in each pair, I was able to get away with not changing our API. Once we start adding support for more sophisticated positioning, we'll need to be able to communicate more than a simple "kerning offset" to the clients of this code.
2023-03-15AK: Clear OrderedHashTable previous/next pointers on removalJelle Raaijmakers
With Clang, the previous/next pointers in buckets of an `OrderedHashTable` are not cleared when a bucket is being shifted up as a result of a removed bucket. As a result, an unfortunate pointer mixup could lead to an infinite loop in the `HashTable` iterator, which was exposed in `HashMap::keys()`. Co-authored-by: Luke Wilde <lukew@serenityos.org>
2023-03-14AK: Rename CaseInsensitiveStringViewTraits to reflect intentgustrb
Now it is called `CaseInsensitiveASCIIStringViewTraits`, so we can be more specific about what data structure does it operate onto. ;)
2023-03-14AK: Add Queue::tail()Andreas Kling
We already had head(), so let's also have tail().
2023-03-13AK: Read and write accumulated BitStream bits directlyTim Schumacher
2023-03-13AK: Remove unneeded overrides for `write_until_depleted` from BitStreamTim Schumacher
2023-03-13AK: Rename Stream::write_entire_buffer to Stream::write_until_depletedTim Schumacher
No functional changes.
2023-03-13AK: Rename Stream::read_entire_buffer to Stream::read_until_filledTim Schumacher
No functional changes.
2023-03-13AK: Rename Stream::{read,write} to Stream::{read_some,write_some}Tim Schumacher
Similar to POSIX read, the basic read and write functions of AK::Stream do not have a lower limit of how much data they read or write (apart from "none at all"). Rename the functions to "read some [data]" and "write some [data]" (with "data" being omitted, since everything here is reading and writing data) to make them sufficiently distinct from the functions that ensure to use the entire buffer (which should be the go-to function for most usages). No functional changes, just a lot of new FIXMEs.
2023-03-13AK: Compute UTF-8 code point lengths using only leading bytesTimothy Flynn
We don't need to decode the entire code point to know its length. This reduces the runtime of decoding a string containing 5 million instances of U+10FFFF from over 4 seconds to 0.9 seconds.
2023-03-11AK: Add FlyString::from_deprecated_fly_string()Kenneth Myhra
Let's add FlyString::from_deprecated_fly_string() so we can use it instead of FlyString::from_utf8(). This will make it easier to detect potential unncessary allocations as we transfer to FlyString.
2023-03-11AK: Forward-declare LexicalPathSam Atkins
And alphabetically sort the list while I'm at it.
2023-03-10Everywhere: Rename equals_ignoring_case => equals_ignoring_ascii_caseAndreas Kling
Let's make it clear that these functions deal with ASCII case only.
2023-03-10AK: Add constexpr floor and roundkleines Filmröllchen
2023-03-09AK: Make FlyString::hash() use the cached hash in StringData if possibleAndreas Kling
This avoids rehashing the string every time.
2023-03-09AK: Replace C-style castsSam Atkins