Commit graph

3168 commits

Author SHA1 Message Date
Daniel Bertalan 8df5bd53da AK: Silence false positive -Warray-bounds warning
This regression has been reported to GCC's Bugzilla:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109727

The formatting change looks like a clang-format 15 bug :(
2023-05-15 07:00:29 +02:00
Ben Wiederhake 173f872cda Meta: Remove unused debug flags, add missing GENERATE_DEBUG
Commands that were helpful while investigating this:
```
grep -P '^set' Meta/CMake/all_the_debug_macros.cmake \
  | sed -Ee 's,set\((.+) ON\)$,\1,' > macros.lst
for i in $(cat macros.lst); do
  echo -n "$i "; git grep -Pn '\b'"$i"'\b' | wc -l
done | tee matches.lst
sort -k2 -n matches.lst
```
2023-05-14 16:01:57 -06:00
Ben Wiederhake 32a777347f AK: Fix typo in instructions for adopt_nonnull_REF_or_enomem 2023-05-13 18:35:02 +02:00
Lucas CHOLLET 4a2ef231b8 AK: Add FixedArray::unchecked_at 2023-05-09 11:18:46 +02:00
Lucas CHOLLET af6dc267d3 AK: Add OutputBufferedStream
This class, in a similar fashion to what has been done with
`InputBufferedStream`, postpones write to the stream until an internal
buffer is full.

This patch also adds the `OutputBufferedFile` alias.
2023-05-09 11:18:46 +02:00
Lucas CHOLLET 8c34959b53 AK: Add the Input word to input-only buffered streams
This concerns both `BufferedSeekable` and `BufferedFile`.
2023-05-09 11:18:46 +02:00
Lucas CHOLLET 48b000a36c AK: Add CircularBuffer::flush_to_stream
In a similar fashion to what have been done with `fill_from_stream`,
this new method allows to write CircularBuffer's data to a Stream
without additional copies.
2023-05-09 11:18:46 +02:00
Kemal Zebari eda2a2f5da AK: Remove must_set() from JsonArray
Due to 582c55a, both `must_set()` and `set()` should be providing the
same behavior. Not only is that a reason to remove `must_set()`, but
it also performs erroneous behavior since it inserts an element at
a specified index instead of modifying an element at that index.
2023-05-09 06:21:34 +02:00
Timothy Flynn d6b786b3fe AK: Use consteval String factories on macOS
Xcode 14.3 ships with clang 15, which supports our usage of consteval to
validate short strings at compile time.
2023-05-08 20:54:31 -06:00
Ben Wiederhake 36ff6187f6 Everywhere: Change spelling of 'behaviour' to 'behavior'
"The official project language is American English […]."
5d2e915623/CONTRIBUTING.md?plain=1#L30

Here's a short statistic of the occurrences of the word "behavio(u)r":

$ git grep -IPioh 'behaviou?r' | sort | uniq -c | sort -n
      2 BEHAVIOR
     24 Behaviour
     32 behaviour
    407 Behavior
    992 behavior

Therefore, it is clear that "behaviour" (56 occurrences) should be
regarded a typo, and "behavior" (1401 occurrences) should be preferred.

Note that The occurrences in LibJS are intentionally NOT changed,
because there are taken verbatim from the specification. Hence:

$ git grep -IPioh 'behaviou?r' | sort | uniq -c | sort -n
      2 BEHAVIOR
     10 behaviour
     24 Behaviour
    407 Behavior
   1014 behavior
2023-05-07 01:05:09 +02:00
Ben Wiederhake ee47c0275e Everywhere: Run spellcheck on all documentation 2023-05-07 01:05:09 +02:00
Tim Schumacher 56d861ebe0 AK: Prevent bit counter underflows in the new BitStream
Our current `peek_bits` function allows retrieving more bits than we can
actually provide, so whenever someone discards the requested bit count
afterwards we were underflowing the value instead.
2023-05-04 20:01:16 +02:00
Kemal Zebari 582c55a1c8 AK: Have JsonArray::set() change values instead of inserting values
Resolves #18618.

8134dcc changed `JsonArray::set()` to insert elements at an index
instead of changing existing elements in-place. Since no behavior
such as `Vector::try_at()` exists yet, it returns nothing.
2023-05-03 21:39:09 +01:00
Ali Mohammad Pur 2306219ef9 AK: Accomodate always-32-bit data member pointers in IntrusiveList
This only exists on windows, but we've made an effort to keep jakt
working on windows, so let's support this silliness.
2023-05-02 17:46:39 +03:30
Daniel Bertalan 00b4976f2c Everywhere: Make Lagom build with GCC 13
GCC 13 was released on 2023-04-26. This commit fixes Lagom build errors
when using an updated host toolchain:
- Adds a workaround for a bug in constraint handling, which made LibJS
  fail to compile: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109683
- Silences the new `-Wdangling-reference` diagnostic globally. It
  produces multiple false positives with no clear way to silence them
  without `#pragmas`.
- Silences `-Wself-move` in `RefPtr` tests as GCC 13 adds this
  previously Clang-exclusive warning.
2023-05-02 07:03:57 -04:00
Dan Klishch 4653b38808 AK: Replace linear exponentiation by binary in MinimalBigInt
This further optimizes floating point parsing (specifically with a large
amount of digits). The commit shaves additional 20% of the run time for
750-digit numbers. No performance degradation is noticeable for small
numbers.
2023-04-30 06:05:54 +02:00
Dan Klishch 80517b5a70 AK: Use helpers from BigIntBase.h in MinimalBigInt
Although it might seem like we've switched to more generic functions,
which must run slower, it is not the case. The time required to parse
"1", for example, decreased by 1%. For numbers with more digits, the
effect is more noticeable: 8-digit numbers are parsed ~5% faster; for
gigantic 750-digit numbers, parsing is 2 times faster.

The later result is achieved by using UFixedBigInt<64>::wide_multiply
instead of u128::operator*(u128).
2023-04-30 06:05:54 +02:00
Dan Klishch 3c900765bc AK: Move taint_for_optimizer to StdLibExtras.h
Additionally, split it into two versions (for IsIntegral<T> -- asking
to place value into register and for !IsIntegral<T> -- asking to place
value into memory with memory clobber), so that Clang is no more
completely confused about `taint_for_optimizer(AK::StringView&)`.
2023-04-30 06:05:54 +02:00
thankyouverycool 9a03e4dd73 AK: Add count() helper to String 2023-04-30 05:48:14 +02:00
Daniel Bertalan c911fb0150 AK: Add Span::align_to
This method returns a sub-span whose data pointer and size is aligned to
a specified alignment.
2023-04-29 08:24:18 +02:00
Aliaksandr Kalenik 4c6564e3c1 AK: Add values() method in HashTable
Add HashTable::values() method that returns all values.
2023-04-28 18:11:44 +02:00
Ali Mohammad Pur 41cf52a623 AK: Make the Optional formatter always available and tweak its format
There's no real reason to make this a debug-only formatter, on top of
that, jakt has a optional formatter that prints None/foo instead of
OptionalNone/Optional(foo), which is more concise anyway, so switch to
that.
2023-04-28 14:55:56 +02:00
MacDue 454ecf24ea AK+LibTimeZone: Add debug only formatter for Optional
I found this handy for debugging, and so might others.

This now also adds a formatter for TimeZone::TimeZone. This is needed
for FormatIfSupported<Optional<TimeZone::TimeZone>> to compile. As
FormatIfSupported sees a formatter for Optional exists, but not that
there's not one for TimeZone::TimeZone.
2023-04-28 09:42:28 +02:00
Ali Mohammad Pur d06057f88b AK: Don't refer to AK::swap() as ::swap()
While swap() is available in the global namespace in normal conditions,
!USING_AK_GLOBALLY will make this name unavailable in the global
namespace, making these calls fail to compile.
2023-04-28 05:56:04 +02:00
Ali Mohammad Pur 7e6341587b AK+Everywhere: Disallow Error::from_string_view(FooString)
That pattern seems to show up a lot in code written by people that
aren't intimately familiar with the lifetime model of Error and Strings.
This commit makes the compiler detect it and present a more helpful
diagnostic than "garbage string at runtime".
2023-04-28 05:55:20 +02:00
Ali Mohammad Pur 7e4e9fdb8f LibWasm: Start implementing WASI
This commit starts adding support for WASI, along with the framework to
implement all the functions (though only a couple are currently
implemented).
2023-04-26 03:47:15 +03:30
Tim Schumacher 5e7c838160 AK: Rename Stream::format() to Stream::write_formatted()
This brings the function name in line with how we usually name those
functions, which is with a `read_` or `write_` prefix depending on what
they do.

While at it, make the internal `_impl` function private and not-virtual,
since there is no good reason to ever override that function.
2023-04-25 07:30:16 +01:00
Cameron Youell ada6dbf636 AK: Use JsonArray::append when parsing array 2023-04-24 09:21:51 +02:00
Cameron Youell 8134dccdc7 AK: Add new failable JsonArray::{append/set} functions
Move all old usages to the more explicit `JsonArray:must_{append/set}`
2023-04-24 09:21:51 +02:00
Zaggy1024 ba5bf412e5 LibThreading: Create WorkerThread class run a single task concurrently
This class can be used to run a task in another thread, and allows the
caller to wait for the task to complete to retrieve any error that may
have occurred.

Currently, it doesn't support functions returning a value on success,
but with some template magic that should be possible. :^)
2023-04-23 23:14:30 +02:00
Peter Brottveit Bock 6f6d6c654d AK: Implement Stream::format(fmtstr, args...)
Based on `out()` and `vout()` from AK/Format.h. As opposed to those,
this propagates errors.

As `Core::File` extends `AK::Stream`, this allows formatted
printing directly on `Core::File`s.
2023-04-23 16:56:06 +02:00
Sam Atkins 892470a912 AK: Add Array::contains_slow() and ::first_index_of(), with tests :^) 2023-04-21 20:44:47 +01:00
Andreas Kling b7e847e58b AK: Fix crash during teardown of self-owning objects
We now null out smart pointers *before* calling unref on the pointee.
This ensures that the same smart pointer can't be used to acquire a new
reference to the pointee after its destruction has begun.

I ran into this when destroying a non-empty IntrusiveList of RefPtrs,
but the problem was more general so this fixes it for all of RefPtr,
NonnullRefPtr, OwnPtr and NonnullOwnPtr.
2023-04-21 18:15:00 +02:00
MacDue 5db1eb9961 AK+Everywhere: Replace URL::paths() with path_segment_at_index()
This allows accessing and looping over the path segments in a URL
without necessarily allocating a new vector if you want them percent
decoded too (which path_segment_at_index() has an option for).
2023-04-15 06:37:04 +02:00
MacDue 35612c6a7f AK+Everywhere: Change URL::path() to serialize_path()
This now defaults to serializing the path with percent decoded segments
(which is what all callers expect), but has an option not to. This fixes
`file://` URLs with spaces in their paths.

The name has been changed to serialize_path() path to make it more clear
that this method will generate a new string each call (except for the
cannot_be_a_base_url() case). A few callers have then been updated to
avoid repeatedly calling this function.
2023-04-15 06:37:04 +02:00
MacDue 5acd40c525 AK+Everywhere: Add ApplyPercentDecoding option to URL getters
The defaults selected for this are based on the behaviour of URL
when it applied percent decoding during parsing. This does mean now
in some cases the getters will allocate, but percent_decode() checks
if there's anything to decode first, so in many cases still won't.
2023-04-15 06:37:04 +02:00
MacDue b9e03071cc AK: Remove unnecessary parameter names in URL.h 2023-04-15 06:37:04 +02:00
Nico Weber afcbdad1e3 AK: Remove workaround for old macOS SDK
https://github.com/SerenityOS/serenity/pull/9716#issuecomment-1508606204
has details.
2023-04-14 19:15:42 +02:00
Nico Weber eae1e61a88 AK: Remove unused AK_ARCH_ defines
ARCH() uses the AK_IS_ARCH_ macros internally since 349e54d537,
and all user code uses the ARCH() macro instead of AK_ARCH_.

(Why it's called ARCH() and not AK_ARCH(), I don't know.)

If any ports not in the main repo use AK_ARCH_, they should switch
to using ARCH() instead.
2023-04-14 19:15:19 +02:00
Nico Weber 97b7e494e4 Everywhere: Use ARCH(AARCH64) instead of AK_ARCH_AARCH64
The former is typo-resistant after 349e54d537, so make use of that.
2023-04-14 19:15:19 +02:00
Nico Weber fc15fc36ce AK: Make math work on arm hosts again
957f89ce4a added some tweaks for serenity-on-aarch64.
It broke anythingelse-on-aarch64 hosts though, so only do these tweaks
when targeting serenity.

(I wonder if AK/Math.h should fall back to the system math routines
when not targeting serenity in general. Would probably help ladybird
performance. On the other hand, the serenity routines would see less
use and hence exposure and love.)
2023-04-14 16:16:42 +02:00
Tim Schumacher b1136ba357 AK: Efficiently resize CircularBuffer seekback copy distance
Previously, if we copied the last byte for a length of 100, we'd
recalculate the read span 100 times and memmove one byte 100 times,
which resulted in a lot of overhead.

Now, if we know that we have two consecutive copies of the data, we just
extend the distance to cover both copies, which halves the number of
times that we recalculate the span and actually call memmove.

This takes the running time of the attached benchmark case from 150ms
down to 15ms.
2023-04-14 10:03:42 +02:00
Timon Kruiper 957f89ce4a AK: Add very naive implementation of {sin,cos,tan} for aarch64
The {sin,cos,tan} functions in AK are used as the implementation of the
same function in libm. We cannot use the __builtin_foo functions as
these would just call the libc functions. This was causing an infinite
loop. Fix this by adding a very naive implementation of
AK::{sin, cos,tan}, that is only valid for small inputs. For the other
functions in this file, I added a TODO() such that we'll crash, instead
of infinite looping.
2023-04-13 20:24:25 +02:00
Sam Atkins 89e55c5297 AK+Tests: Add Vector::find_first_index_if() 2023-04-13 09:53:47 +02:00
Nico Weber f56b897622 Everywhere: Fix a few typos
Some even user-visible!
2023-04-12 19:37:35 +02:00
Nico Weber 077164ae15 AK: Make grepping for "lerp" find mix() 2023-04-12 15:23:51 +02:00
Tim Schumacher adfda6a271 AK: Remove the Endian bytes accessor
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-12 07:33:15 -04:00
MacDue 8283e8b88c AK: Don't store parts of URLs percent decoded
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-12 07:40:22 +02:00
networkException 9915fa72fb AK+Everywhere: Use Optional for URLParser::parse's base_url parameter 2023-04-11 16:28:20 +02:00
Tim Ledbetter 54539c42c2 AK: Allow human_readable_size_long to use a thousands separator 2023-04-11 13:03:30 +02:00
Tim Ledbetter 72ea046b68 AK: Add option to the string formatter to use a digit separator
`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-11 13:03:30 +02:00
Rodrigo Tobar 5a8373c6b9 LibCore: Fix corner case for files without newlines
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-09 18:09:23 -06:00
Andreas Kling e1f5aae632 AK: Bake CLion IDE check into AK_COMPILER_CLANG
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-08 13:43:25 +02:00
Timothy Flynn 4d9c14ca67 AK: Allow specifying a minimum value for IDs returned by IDAllocator 2023-04-07 16:02:22 +02:00
Kenneth Myhra d6cf9f5329 AK: Add FlyString::is_one_of for variadic string comparison 2023-04-06 23:49:08 +02:00
stelar7 6163f607c0 AK: Add to_string() for IPv4Address 2023-04-06 09:57:31 +03:30
Tim Schumacher b88c58b94c AK+LibCompress: Break when seekback copying to a full CircularBuffer
Otherwise, we just end up infinitely looping while waiting for more
space in the destination.
2023-04-05 07:30:38 -04:00
Tim Schumacher 767fb01a8c AK: Report copied bytes when seekback copying from CircularBuffer
Otherwise, we have no way of determining whether our copy was truncated
by accident.
2023-04-05 07:30:38 -04:00
Tim Schumacher 997e745e87 AK: Properly limit the internal seekback span for CircularBuffer
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-05 07:30:38 -04:00
Timothy Flynn 15532df83d AK+Everywhere: Change AK::fill_with_random to accept a Bytes object
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-03 15:53:49 +02:00
Timothy Flynn 5c045b6934 AK: Add templated Span<u8> and Span<u8 const> constructors for C-arrays
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-03 15:53:49 +02:00
Timothy Flynn f7960ffbe3 AK: Prevent passing lengths greater than 256 to getentropy()
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-03 15:53:49 +02:00
Timothy Flynn eed956b473 AK: Increase LittleEndianOutputBitStream's buffer size and remove loops
This is very similar to the LittleEndianInputBitStream bit buffer change
from 8e834d4bb2.

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-04-02 10:54:37 +02:00
Timothy Flynn 8b56d82865 AK+LibCompress: Remove the Deflate back-reference intermediate buffer
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-31 06:56:11 +02:00
Timothy Flynn 7319deb03d AK: Remove BitStream workaround for now-resolved BufferedStream behavior
The issue was that the buffer would only be filled if it was empty.
2023-03-30 08:47:22 +02:00
Timothy Flynn 13573a6c4b AK: Refill a BufferedStream when it has less than the requested size
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-30 08:47:22 +02:00
Timothy Flynn 5c38b14045 AK: Remove arbitrary 1 KB limit when filling a BufferedStream's buffer
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-30 08:47:22 +02:00
Daniel Bertalan 0016f63547 AK: Fix Clang 16 UBSan issue with zero-length Array
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-29 21:35:53 -04:00
Nico Weber e1f8443db0 AK: Fix build with Xcode 14.2's clang
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-29 06:28:55 -04:00
Timothy Flynn 8e834d4bb2 AK: Increase LittleEndianInputBitStream's buffer size and remove loops
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-29 07:19:14 +02:00
Timothy Flynn 9423662107 AK: Add NumericLimits::digits to return the number of digits in a type
Analogous to std::numeric_limits<T>::digits.
2023-03-29 07:19:14 +02:00
Ali Mohammad Pur a28aba7663 AK: Add DeprecatedString::from_utf8(StringView)
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-28 15:55:35 +01:00
Sam Atkins b876e97719 AK: Expose the current position of a Utf8CodePointIterator as a pointer 2023-03-22 19:45:40 +01:00
Tim Schumacher 52d9fc92f1 AK: Expose the seekback limit of CircularBuffer 2023-03-21 10:25:13 +01:00
Tim Schumacher e62183f0ba AK: Add a Stream wrapper that counts read bytes 2023-03-21 10:25:13 +01:00
Tim Schumacher d1f6a28ffd AK: Move ConstrainedStream from LibWasm and limit discarding 2023-03-21 10:25:13 +01:00
Timothy Flynn 2671d4280f AK: Export FlyString from the forwarding header 2023-03-18 19:50:45 +01:00
Andreas Kling d38a3ca9eb LibGfx/OpenType: Add some initial support for GPOS glyph positioning
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-17 09:36:20 +01:00
Jelle Raaijmakers 954d660094 AK: Clear OrderedHashTable previous/next pointers on removal
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-15 21:43:52 +01:00
gustrb 5141c86587 AK: Rename CaseInsensitiveStringViewTraits to reflect intent
Now it is called `CaseInsensitiveASCIIStringViewTraits`, so we can be
more specific about what data structure does it operate onto. ;)
2023-03-14 21:34:32 +00:00
Andreas Kling f8c075f2b1 AK: Add Queue::tail()
We already had head(), so let's also have tail().
2023-03-14 16:52:44 +01:00
Tim Schumacher e007279315 AK: Read and write accumulated BitStream bits directly 2023-03-13 15:16:20 +00:00
Tim Schumacher b623dda765 AK: Remove unneeded overrides for write_until_depleted from BitStream 2023-03-13 15:16:20 +00:00
Tim Schumacher ecd1862859 AK: Rename Stream::write_entire_buffer to Stream::write_until_depleted
No functional changes.
2023-03-13 15:16:20 +00:00
Tim Schumacher a3f73e7d85 AK: Rename Stream::read_entire_buffer to Stream::read_until_filled
No functional changes.
2023-03-13 15:16:20 +00:00
Tim Schumacher d5871f5717 AK: Rename Stream::{read,write} to Stream::{read_some,write_some}
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-13 15:16:20 +00:00
Timothy Flynn 1d5b45f7d9 AK: Compute UTF-8 code point lengths using only leading bytes
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-13 15:16:02 +00:00
Kenneth Myhra e28a6d5da4 AK: Add FlyString::from_deprecated_fly_string()
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-11 18:32:33 +00:00
Sam Atkins 82f58b8af0 AK: Forward-declare LexicalPath
And alphabetically sort the list while I'm at it.
2023-03-11 13:22:57 +00:00
Andreas Kling a504ac3e2a Everywhere: Rename equals_ignoring_case => equals_ignoring_ascii_case
Let's make it clear that these functions deal with ASCII case only.
2023-03-10 13:15:44 +01:00
kleines Filmröllchen b38beb106e AK: Add constexpr floor and round 2023-03-10 04:07:14 -07:00
Andreas Kling d517e7fb3a AK: Make FlyString::hash() use the cached hash in StringData if possible
This avoids rehashing the string every time.
2023-03-09 21:54:59 +01:00
Sam Atkins 067d0689c5 AK: Replace C-style casts 2023-03-09 21:43:54 +01:00
Linus Groh e76394d96c AK: Remove infallible version of StringBuilder::to_byte_buffer
Also drop the try_ prefix from the fallible function, as it is no longer
needed to distinguish the two.
2023-03-09 15:51:00 +00:00
Karol Baraniecki b4b283670d AK: Introduce a fallible version of StringBuilder::to_byte_buffer
Name it StringBuilder::try_to_byte_buffer accordingly :^)
2023-03-09 12:59:57 +00:00
Timothy Flynn 1393ed2000 AK+LibUnicode: Implement String::equals_ignoring_case without allocating
We currently fully casefold the left- and right-hand sides to compare
two strings with case-insensitivity. Now, we casefold one code point at
a time, storing the result in a view for comparison, until we exhaust
both strings.
2023-03-08 18:57:53 +00:00
Timothy Flynn 4aee4e80bd AK: Add a Utf32View::substring_view overload to take only an offset
This is for convenience, and matches our other UTF-N views.
2023-03-08 18:57:53 +00:00
Timothy Flynn 515fca4f7a AK: Make String::contains(code_point) handle non-ASCII
We currently only accept a char, instead of a full code point.
2023-03-08 14:16:47 +00:00
Timothy Flynn f882581e91 AK: Make String::{starts,ends}_with(code_point) handle non-ASCII
We currently pass the code point to StringView::{starts,ends}_with,
which actually accepts a single char, thus cannot handle non-ASCII
code points.
2023-03-08 14:16:47 +00:00
Andreas Kling 629b6462dc AK: Add FlyString::equals_ignoring_ascii_case()
This is similar to equals_ignoring_case() but only cares about ASCII
case insensitivity.
2023-03-08 13:19:15 +01:00
Andreas Kling 5aa12da959 AK+Kernel: Remove all the Nonnull*PtrVector classes 2023-03-06 23:46:36 +01:00
Andreas Kling d57b09b7cf AK: Remove specialized shuffle for NonnullPtrVector 2023-03-06 23:46:36 +01:00
Kenneth Myhra 03ceca4ca1 AK: Add FlyString::to_deprecated_fly_string()
This adds the conversion function to_deprecated_fly_string() to enable
conversion from new FlyString to DeprecatedFlyString.
2023-03-05 18:25:59 +00:00
Dan Klishch 882dcfaddb AK+LibAudio: Remove UFixedBigInt::my_size 2023-03-05 13:49:43 +01:00
Dan Klishch 2d27c98659 AK: Implement Knuth's algorithm D for dividing UFixedBigInt's 2023-03-04 22:10:03 -07:00
Dan Klishch 2470fab05e AK: Delete unused and untested sqrt, pow and pow_mod from UFixedBigInt 2023-03-04 22:10:03 -07:00
Dan Klishch 8f8e31e780 AK+LibCrypto: Delete 64x64 wide multiplication workarounds
Now UFixedBigInt exposes API to do wide multiplications of this kind
efficiently.
2023-03-04 22:10:03 -07:00
Dan Klishch 67ec347bfa AK: Rewrite UFixedBigInt using the framework from BigIntBase.h 2023-03-04 22:10:03 -07:00
Dan Klishch e132570284 AK: Introduce "BigIntBase.h" for common simple operations on big ints 2023-03-04 22:10:03 -07:00
Dan Klishch 2a6f5ff441 AK: Move compiletime_fail to StdLibExtras.h
This function will be used in the next commit in "BigIntBase.h".
2023-03-04 22:10:03 -07:00
nipos e35a858bde AK: Remove signbit definition to prevent conflict in FixedPoint 2023-03-04 21:34:54 -07:00
nipos aa9f1ee889 AK: Add support for Solaris to StackInfo 2023-03-04 21:34:54 -07:00
nipos d65c912c09 AK: Add Solaris to platform detection 2023-03-04 21:34:54 -07:00
Andrew Kaster c1983244a2 AK: Add StackInfo implementation for Windows
This prevents a warning when compiling jakt that it's not implemented.
2023-03-04 13:59:04 +01:00
Sam Atkins 3d8cc2257f LibCMake: Introduce a CMake lexer 2023-03-04 05:43:43 -07:00
Sam Atkins ca4cc03269 AK: Format Debug.h.in
Indented #cmakedefine01 is supported since CMake 3.10:
https://cmake.org/cmake/help/latest/release/3.10.html#commands

We're on 3.16, and the minimum required for Serenity itself is 3.25, so
this should be fine. And it makes CLion's auto-formatter much happier!
2023-03-04 05:43:43 -07:00
Dan Klishch 4536b80a62 AK+readelf: Issue error when using ARCH(arch) with nonexistent arch
This disallows erroneous `#if ARCH(x86_64)` (note lowercase x).
2023-03-03 21:53:41 +01:00
Timothy Flynn da0d000909 AK: Ensure short String instances are valid UTF-8
We are currently only validating long strings.
2023-03-03 11:46:42 -05:00
Timothy Flynn 434ca78425 AK: Protect Utf8View against inclusion in the Kernel
It will soon be included in the Kernel by way of String.h. Utf8View
includes DeprecatedString, which is not allowed in the Kernel.
2023-03-03 11:46:42 -05:00
Timothy Flynn c4d78c29a2 AK: Invalidate overlong UTF-8 code point encodings
For example, the code point U+002F could be encoded as UTF-8 with the
bytes 0x80 0xAF. This trick has historically been used to bypass
security checks.
2023-03-03 11:46:42 -05:00
Timothy Flynn 796a615bc1 AK: Replace UTF-8 string validation with a constexpr implementation
This will allow validating UTF-8 strings at compile time, such as from
String::from_utf8_short_string.
2023-03-03 11:46:42 -05:00
Linus Groh 45dc3d8a3e AK: Add String::ends_with{,_bytes}() 2023-03-03 11:02:21 +00:00
Linus Groh bfdbb4b6ed AK: Add missing const qualifier to HashCompatible HashMap::contains() 2023-03-03 11:02:21 +00:00
Nico Weber b898a46d7f AK: Make FixedPoint(FloatingPoint) ctor round instead of truncating
This is needed to have code for creating an in-memory sRGB profile using
the (floating-ppoint) numbers from the sRGB spec and having the
fixed-point values in the profile match what they are in other software
(such as GIMP).

It has the side effect of making the FixedPoint ctor no longer constexpr
(which seems fine; nothing was currently relying on that).

Some of FixedPoint's member functions don't round yet, which requires
tweaking a test.
2023-03-03 09:23:02 +00:00
Kenneth Myhra 843c9d6cd7 AK: Add new String constructor to URL 2023-03-01 22:44:20 +00:00
Sam Atkins c06f4ac6f5 AK+Everywhere: Make GenericLexer::ignore_until() stop before the value
`consume_until(foo)` stops before foo, and so does
`ignore_until(Predicate)`, so let's make the other `ignore_until()`
overloads consistent with that so they're less confusing.
2023-02-28 12:55:10 +00:00
Ali Mohammad Pur db886fe18b Userland+AK: Stop using getopt() for ArgsParser
This commit moves the implementation of getopt into AK, and converts its
API to understand and use StringView instead of char*.
Everything else is caught in the crossfire of making
Option::accept_value() take a StringView instead of a char const*.

With this, we must now pass a Span<StringView> to ArgsParser::parse(),
applications using LibMain are unaffected, but anything not using that
or taking its own argc/argv has to construct a Vector<StringView> for
this method.
2023-02-28 15:52:24 +03:30
Ali Mohammad Pur 79e4027480 AK: Add two starts_with{bytes,}() APIs to String 2023-02-28 15:52:24 +03:30
Tim Ledbetter 6b2f3ad6c8 AK: Fix DeprecatedString::bijective_base_from for large numbers
The output of the DeprecatedString::bijective_base_from() is now
correct for numbers larger than base^2.

This makes column names display correctly in Spreadsheet.
2023-02-26 21:06:21 +03:30
kleines Filmröllchen 961e263129 AK: Add FixedPoint::clamp 2023-02-25 20:49:41 -07:00
Timothy Flynn 5eec76b441 AK: Use the same consteval condition on _short_string as its factory
This fixes the build with Apple Clang.
2023-02-25 22:25:05 +01:00
Linus Groh 85414d9338 AK: Add operator""_{short_,}string to create a String from a literal
We briefly discussed this when adding the new String type but couldn't
settle on a name. However, having to use String::from_utf8() on every
literal string is a bit unwieldy, so let's have these options available!

Naming-wise '_string' is not as short as 'sv' but should be relatively
clear; it also matches '_bigint' and '_ubigint' in length.
'_short_string' may be longer than the actual string itself, but it's
still an improvement over the static function :^)

Since our C++ source files are UTF-8 encoded anyway, it should be
impossible to create a string literal with invalid UTF-8, so including
that in the name is not as important as in the function that can receive
arbitrary data.
2023-02-25 20:51:49 +01:00
Liav A 12b7328c22 AK+Kernel: Add includes before removing Kernel/ProcessExposed.h
Apparently without this file, we won't be able to compile due to missing
includes to TimeManagement and KBufferBuilder.
2023-02-24 22:14:18 +01:00
Nico Weber f7e152d049 LibGfx: Add scaffolding for a webp decoder
At the moment, this processes the RIFF chunk structure and extracts
the ICCP chunk, so that `icc` can now print ICC profiles embedded
in webp files. (And are image files really more than containers
of icc profiles?)

It doesn't even decode image dimensions yet.

The lossy format is a VP8 video frame. Once we get to that, we
might want to move all the image decoders into a new LibImageDecoders
that depends on both LibGfx and LibVideo. (Other newer image formats
like heic and av1f also use video frames for image data.)
2023-02-24 19:44:20 +01:00
Timothy Flynn 832e9b8302 AK: Prepare Utf32View for use within templated LibGfx contexts
Forward declare its iterator and add a peek() method analagous to
Utf8CodePointIterator::peek().
2023-02-22 10:14:36 +01:00
Timothy Flynn 0f20586346 AK: Add formatters for Utf8View and Utf32View
Useful for debugging, especially in templated contexts.
2023-02-22 10:14:36 +01:00
Tim Schumacher 9096b4d893 AK: Ensure that we fill the whole String when reading from a Stream 2023-02-21 22:28:15 -07:00
Hediadyoin1 fd8c54d720 AK: Add take_first to HashTable and rename pop to take_last
This naming scheme matches Vector.

This also changes `take_last` to move the value it takes, and delete by
known pointer, avoiding a full lookup and potential copies.
2023-02-21 22:13:06 +01:00
Hediadyoin1 93945062a7 AK: Update HashTables head and tail when shifting during deletion
Otherwise we end up with invalid pointers to them, breaking iteration.
2023-02-21 22:13:06 +01:00
Andrew Kaster 0ea697ace5 AK: Add String::from_stream method
The caller is responsible for determining how long the string is that
they want to read.
2023-02-21 10:57:44 +01:00
Andreas Kling 7ac7a73758 Revert "AK: Disallow constness laundering in RefPtr and NonnullRefPtr"
This reverts commit 3c7a0ef1ac.

This broke Jakt, which will need some adjustments to its code generation
before we can commit to being this strict.
2023-02-21 09:22:18 +01:00
Andreas Kling 3c7a0ef1ac AK: Disallow constness laundering in RefPtr and NonnullRefPtr
Until now, it was possible to assign a RP<T const> or NNRP<T const>
to RP<T> or NNRP<T>. This meant that the constness of the T was lost.

We had a lot of code that relied on this sloppiness, and by the time
you see this commit, I hopefully found and fixed all of it. :^)
2023-02-21 00:54:04 +01:00
Andreas Kling e08c55dd8d AK: Make String const-correct internally 2023-02-21 00:54:04 +01:00
Andreas Kling a56dfd5c77 AK: Make Deprecated{Fly,}String and StringImpl const-correct 2023-02-21 00:54:04 +01:00
Andreas Kling b2b942b4ec AK: Stop NonnullPtrVector from making accessed elements const 2023-02-21 00:54:04 +01:00
nipos 5b147f29ab AK/StackInfo: Add support for NetBSD 2023-02-20 18:44:36 +01:00
Andrew Kaster a2ef168d75 AK: Allow zero-valued signed size types in format strings 2023-02-19 13:49:07 +01:00
nipos c42e949f5b AK/StackInfo: Add support for OpenBSD pthreads 2023-02-19 11:44:45 +01:00
Sam Atkins b5eb2ee478 AK: Make FlyString(String) constructor implicit
This stops us needing a lot of ugly `FlyString { ... }` wrappers. THis
is the behavior that `DeprecatedFlyString(DeprecatedString)` has so it
should be fine.
2023-02-19 00:51:16 +01:00
Lucas CHOLLET 856d0202f2 LibGfx: Rename JPGLoader to JPEGLoader
The patch also contains modifications on several classes, functions or
files that are related to the `JPGLoader`.

Renaming include:
 - JPGLoader{.h, .cpp}
 - JPGImageDecoderPlugin
 - JPGLoadingContext
 - JPG_DEBUG
 - decode_jpg
 - FuzzJPGLoader.cpp
 - Few string literals or texts
2023-02-18 23:56:24 +01:00