Commit graph

2101 commits

Author SHA1 Message Date
Tim Schumacher 67a579aab0 AK: Add a basic formatter for wchar_t 2021-10-03 11:13:50 +00:00
Andreas Kling 87290e300e AK: Simplify Utf16View::operator==(Utf16View) 2021-10-02 18:32:56 +02:00
Andreas Kling 024367d82e LibJS+AK: Use Vector<u16, 1> for UTF-16 string storage
It's very common to encounter single-character strings in JavaScript on
the web. We can make such strings significantly lighter by having a
1-character inline capacity on the Vectors.
2021-10-02 17:39:38 +02:00
Andreas Kling 77f0e57b27 RequestServer: Don't hide the SIGINFO state dump behind a debug macro
Until we're confident that RequestServer doesn't need this runtime debug
dump helper, it's much nicer if everyone has it built in, so they can
simply send a SIGINFO if they see it acting up.
2021-10-01 20:17:15 +02:00
Nico Weber 5e21759f3d AK: Fix typos 2021-10-01 01:33:43 +01:00
Ali Mohammad Pur 398435277b RequestServer: Use an OwnPtr for cached connections
Otherwise we'd end up trying to delete the wrong connection if a
connection made before us is deleted.
Fixes _some_ RequestServer spins (though not all...).
This commit also adds a small debug mechanism to RequestServer (which
can be enabled by turning REQUEST_SERVER_DEBUG on), that can dump all
the current active connections in the cache, what they're doing, and how
long they've been doing that by sending it a SIGINFO.
2021-09-29 11:47:18 +02:00
Rodrigo Tobar 69b64a6b04 AK: Accept StringView in LexicalPath::join
The first argument for LexicalPath::join was a String const&, which
resulted in an unnecessary memory copy when invoked with a StringView.
Changing the type of the parameter to StringView avoids the extra cost.

This was noticed while working on #10230.
2021-09-28 18:06:06 +03:00
Idan Horowitz b56b0ba689 AK: Eliminate avoidable strlen call in String::matches
We already know the length of these substrings, so there's no need to
check their lengths using strlen in the StringView(char*) constructor.

This patch also removes an accidental 1-byte OOB read that was left over
from when this method received null-terminated char pointers instead of
string views, as well removes the unnecessary lambda call (two of the
checks were impossible, and this was only called in one place, so we can
just inline it)
2021-09-28 00:31:45 +02:00
Ben Wiederhake 743470c8f2 AK: Introduce ability to default-initialize a Variant
I noticed that Variant<Empty, …> is a somewhat common pattern while
working on #10080, and this will simplify a few use-cases. :^)
2021-09-21 04:22:52 +04:30
Andrew Kaster 61ad239ee0 AK: Remove unnecessary include of <new> for non-__serenity__ builds
We already include `<new>` in AK/kmalloc.h when KERNEL is not defined,
which applies to all non-`__serenity__` builds.
2021-09-20 00:39:46 +00:00
Andrew Kaster da87497e61 AK+LibC: Remove SERENITY_LIBC_BUILD guard around <initializer_list>
This was required before commit 5f724b6ca1
when we were building LibC before libstdc++ headers were available in
the sysroot. However as noted in that commit, we never actually needed
to be building LibC before libstdc++, so we can go ahead and remove this
ancient hack.
2021-09-20 00:39:46 +00:00
Andrew Kaster 210b0b883b AK: Remove unused ifdef for BUILDING_SERENITY_TOOLCHAIN
The only use of this define was removed in commit
5f724b6ca1, over a year ago.

The define was there to prevent the LibC build we built before libstdc++
from complaining about missing libgcc symbols. However, as noted in that
commit, we never actually needed to build LibC at all.
2021-09-20 00:39:46 +00:00
Andreas Kling 391352c112 AK: Inline all the trivial Utf8View functions
This improves parsing time on a large chunk of JS by ~3%.
2021-09-18 19:54:24 +02:00
Andreas Kling 1be4cbd639 AK: Make Utf8View constructors inline and remove C string constructor
Using StringView instead of C strings is basically always preferable.
The only reason to use a C string is because you are calling a C API.
2021-09-18 19:54:24 +02:00
Mustafa Quraish 27f28998b1 AK/Vector: Add Vector::reverse() method
This reverses the contents of the vector in-place.
2021-09-17 16:56:59 +00:00
Brian Gianforcaro 14eb736e22 AK: Reduce the scope of fraction_string to where it's needed
pvs-studio flagged this a potential optimization, as we only
need to really construct the fraction_string if is_double is
true.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro c192c303d2 AK: Use default constructor/destructor instead of declaring an empty one
Default implementations allow for more optimizations.
See: https://pvs-studio.com/en/docs/warnings/v832/
2021-09-16 17:17:13 +02:00
Linus Groh cbdd069279 AK: Rename the local variable in the TRY() macro to avoid name clashes
"result" is a tad bit too generic to provide a clash-free experience -
we found instances in LibJS where this breaks already. Essentially this
doesn't work:

    auto foo = TRY(bar(result));

Because it expands to the following within the TRY() scope:

    {
        auto result = bar(result);
        ...
    }

And that of course fails:

    error: use of ‘result’ before deduction of ‘auto’

The simple solution here is to use a name that is much less likely to
clash with anything used in the expression ("_temporary_result"). :^)
2021-09-15 23:46:53 +01:00
Ali Mohammad Pur ccb53c64e9 AK: Add an abstraction over multiple disjoint buffers
DisjointChunks<T> provides a nice interface over multiple sequential
Vector<T>'s, allowing the user to iterate over/index into/slice from
said buffers as if they were a single contiguous buffer.
To work with views on such objects, DisjointSpans<T> is provided, which
has the same behaviour but does not own the underlying objects.
2021-09-14 21:33:15 +04:30
Idan Horowitz 30849b10d5 AK: Move the path argument of URL::append_path instead of copying it 2021-09-14 00:14:45 +02:00
Idan Horowitz d6cfa34667 AK: Make URL::m_port an Optional<u16>, Expose raw port getter
Our current way of signalling a missing port with m_port == 0 was
lacking, as 0 is a valid port number in URLs.
2021-09-14 00:14:45 +02:00
Idan Horowitz 1c9c43785d AK: Add URL::cannot_have_a_username_or_password_or_port
As defined by the URL specification:
https://url.spec.whatwg.org/#cannot-have-a-username-password-port
2021-09-14 00:14:45 +02:00
Idan Horowitz 929af64a67 AK: Change URL::cannot_be_a_base_url, URL::is_valid return type to bool
There's no need to return a const reference (8 bytes) when the value is
always used as a temporary bool (1 byte).
2021-09-14 00:14:45 +02:00
Idan Horowitz 55b67ba7a7 AK: Accept optional url and state override parameters in URLParser
These are required in the specification and used by the web's URL
built-in, this commit also removes the Badge<AK::URL> from URLParser
to allow other classes that need to call the parser directly like the
web's URL built-in to do so.
2021-09-14 00:14:45 +02:00
Idan Horowitz 6fa4fc8353 AK: Add URL::serialize_origin based on HTML's origin definition 2021-09-14 00:14:45 +02:00
James Puleo ae6862cb2d AK: Remove unimplemented method fill_buffer from UUID 2021-09-13 20:19:34 +02:00
Ali Mohammad Pur 25f43ea0a1 AK: Make Span::operator==() comply with the ISO C++ idea of operator==
This should:
- Accept const& on both sides
- Not involve implicit conversions on either side

otherwise the argument order would be deemed significant, and trip this
warning.
2021-09-13 14:38:53 +04:30
Ali Mohammad Pur a42c7757d3 AK: Switch Span.h to east-const style 2021-09-13 14:38:53 +04:30
Ali Mohammad Pur a72eea6408 AK: Give BumpAllocator a single-block cache
This avoid excessive mmap/munmap traffic in normal operation.
2021-09-13 14:38:53 +04:30
Ali Mohammad Pur 913382734c AK: Allow RBTree::find_largest_not_above_iterator() to fail
Previously this function would've crashed if the key failed to match any
entry.
2021-09-13 14:38:53 +04:30
Ali Mohammad Pur 27e3589f61 AK+Kernel: Avoid unescaped control chars in append_escaped_for_json()
Otherwise it could produce invalid JSON.
2021-09-13 14:38:53 +04:30
Ali Mohammad Pur a21a3c2620 AK: Make traits for NonnullOwnPtr use ptr_hash instead of int_hash
Otherwise they'd be truncating the pointer in 64-bit builds.
2021-09-13 14:38:53 +04:30
Brian Gianforcaro ff1e5aa935 AK: Add secure_zero() implementation so it can be used on all platforms
Serenity has explicit_bzero() in LibC with the same implementation,
however we need to be able to use this from Lagom on all platforms
that we support building serenity on. I've implemented it in AK for
this reason.
2021-09-13 00:02:42 +02:00
Brian Gianforcaro 871ef7a735 AK+LibCore: Standardize on AK_OS_MACOS instead of __APPLE__
We use our custom platform definitions in most places, remove
the few remaining places we weren't using `AK_OS_MACOS`.
2021-09-12 18:31:10 +02:00
Brian Gianforcaro 54fe0c8855 AK: Add the ability to hash the contents of a AK::HashMap 2021-09-12 16:39:23 +02:00
Peter Elliott d28459fb11 AK: Escape '"' in escape_html_entities 2021-09-12 12:17:16 +02:00
Idan Horowitz 6704961c82 AK: Replace the mutable String::replace API with an immutable version
This removes the awkward String::replace API which was the only String
API which mutated the String and replaces it with a new immutable
version that returns a new String with the replacements applied. This
also fixes a couple of UAFs that were caused by the use of this API.

As an optimization an equivalent StringView::replace API was also added
to remove an unnecessary String allocations in the format of:
`String { view }.replace(...);`
2021-09-11 20:36:43 +03:00
Idan Horowitz 6d2b003b6e AK: Make String::count not use strstr and take a StringView
This was needlessly copying StringView arguments, and was also using
strstr internally, which meant it was doing a bunch of unnecessary
strlen calls on it. This also moves the implementation to StringUtils
to allow API consistency between String and StringView.
2021-09-11 20:36:43 +03:00
Ben Wiederhake 9413dddb8b AK: Forbid creating StringView from temporary FlyString 2021-09-11 13:22:51 +03:00
Ben Wiederhake f6d0955a46 AK: Forbid creating StringView from temporary ByteBuffer 2021-09-11 13:22:51 +03:00
Idan Horowitz 6348b63476 Kernel: Add kernelearlyputstr and use it in dbgln in very-early boot
This variant of dbgputstr does not lock the global log lock, as it is
called before the current or any other processor was initialized,
meaning that:
A) The $gs base was not setup yet, so we cannot enter into critical
   sections, and as a result we cannot use SpinLocks
B) No other processors may try to print at the same time anyway
2021-09-10 22:58:08 +03:00
Idan Horowitz 18d2a74e62 AK: Only try and get the Processor::current_id when it was initialized
This caused a null pointer dereference on early boot, since the gs_base
was not set yet.
2021-09-10 22:58:08 +03:00
Ali Mohammad Pur 14c8373eb0 AK+Kernel: Reduce the number of template parameters of IntrusiveRBTree
This makes the user-facing type only take the node member pointer, and
lets the compiler figure out the other needed types from that.
2021-09-10 18:05:46 +03:00
Ali Mohammad Pur 5a0cdb15b0 AK+Everywhere: Reduce the number of template parameters of IntrusiveList
This makes the user-facing type only take the node member pointer, and
lets the compiler figure out the other needed types from that.
2021-09-10 18:05:46 +03:00
Hendiadyoin1 93cf01ad7d AK: Mark HashTable::size_in_bytes() as constexpr 2021-09-10 14:33:53 +00:00
Hediadyoin1 1aa527f5b6 AK: Add OOM safe interface to HashTable/Map
This adds a new HashSetResult only returned by try_set, to signal
allocation failure during setting.
2021-09-10 14:33:53 +00:00
Idan Horowitz 679bde06ed AK: Remove a redundant double find-call in HashMap::ensure
If the value was found there's no reason to search for it again.
2021-09-10 15:26:41 +03:00
Idan Horowitz 0279fb4dd3 AK: Add key getter to IntrusiveRedBlackTreeNode 2021-09-08 19:17:07 +03:00
Idan Horowitz cb9720baab AK: Set IntrusiveRBTree Node key on insertion instead of construction
This makes the API look much nicer.
2021-09-08 19:17:07 +03:00
Idan Horowitz 1db9250766 AK: Make IntrusiveRedBlackTree capable of holding non-raw pointers
This is completely based on e4412f1f59
and will allow us to convert some AK::HashMap users in the kernel.
2021-09-08 19:17:07 +03:00