Commit graph

2727 commits

Author SHA1 Message Date
Agustin Gianni 9a2ee5a9dd AK: Add DeprecatedString::find_last(StringView)
This adds the the method DeprecatedString::find_last() as wrapper for
StringUtils::find_last for the StringView type.
2022-12-20 11:24:05 +01:00
Jelle Raaijmakers 25f2e4981c AK: Stop using DeprecatedString in Base64 encoding 2022-12-20 10:34:19 +01:00
Jelle Raaijmakers 99c1b634fc AK: Stop using DeprecatedString in UUID 2022-12-20 10:34:19 +01:00
Andreas Kling f11e6beca8 AK: Use __has_builtin() in Checked.h
Instead of avoiding overflow-checking builtins with AK_COMPILER_CLANG,
we can use the preprocessor's __has_builtin() mechanism to check if
they are available.
2022-12-19 09:29:12 -05:00
Lenny Maiorani f2336d0144 AK+Everywhere: Move custom deleter capability to OwnPtr
`OwnPtrWithCustomDeleter` was a decorator which provided the ability
to add a custom deleter to `OwnPtr` by wrapping and taking the deleter
as a run-time argument to the constructor. This solution means that no
additional space is needed for the `OwnPtr` because it doesn't need to
store a pointer to the deleter, but comes at the cost of having an
extra type that stores a pointer for every instance.

This logic is moved directly into `OwnPtr` by adding a template
argument that is defaulted to the default deleter for the type. This
means that the type itself stores the pointer to the deleter instead
of every instance and adds some type safety by encoding the deleter in
the type itself instead of taking a run-time argument.
2022-12-17 16:00:08 -05:00
Eli Youngs 950b36f95d AK: Add a try_ensure() method to HashMap 2022-12-16 10:41:56 -07:00
Eli Youngs a2024cfb69 AK: Support popping an arbitrary element from a HashTable 2022-12-16 10:41:56 -07:00
Timothy Flynn d28c9ba054 AK: Synchronize explicit instantiations of to_int and to_uint
1. Ensure long and long long are instantiated for to_int.
2. Ensure long and long long are not instantiated for to_uint.
2022-12-16 10:06:26 +01:00
Lucas CHOLLET 34c13eff11 AK: Add OwnPtrWithCustomDeleter
This class is a smart pointer that let you provide a custom deleter to
free the pointer.

It is quite primitive compared to other smart pointers but can still be
useful when interacting with C types that provides a custom `free()`
function.
2022-12-15 13:38:13 +00:00
kleines Filmröllchen 026cc3d4b9 AK: Add Span to Array conversion function 2022-12-15 00:21:00 -07:00
Poseydon42 bdd7531bf5 AK: Create relative path even if prefix is not an ancestor of the path 2022-12-14 15:11:03 +00:00
Ali Mohammad Pur b367da592c AK: Bring back the AK_DONT_REPLACE_STD #define
This was removed in a910961f37d1da9dafb6385e348266746354cf98 in favour
of the more general USING_AK_GLOBALLY #define, but Ladybird (and
probably other projects) depend on the smaller hammer to include STL
headers and keep the USING_AK_GLOBALLY behaviour, so put it back and
preserve its behaviour.
2022-12-14 12:56:01 +01:00
Ali Mohammad Pur f96a3c002a Everywhere: Stop shoving things into ::std and mentioning them as such
Note that this still keeps the old behaviour of putting things in std by
default on serenity so the tools can be happy, but if USING_AK_GLOBALLY
is unset, AK behaves like a good citizen and doesn't try to put things
in the ::std namespace.

std::nothrow_t and its friends get to stay because I'm being told that
compilers assume things about them and I can't yeet them into a
different namespace...for now.
2022-12-14 11:44:32 +01:00
Ali Mohammad Pur 72514d6915 AK: Make Types.h not export its functions if !USING_AK_GLOBALLY 2022-12-14 11:44:32 +01:00
kleines Filmröllchen 5b4818df22 AK: Make Variant's index type public
This will allow the IPC system to use the exact required index type,
saving transmission space, once it can send variants.
2022-12-13 10:24:59 -05:00
Ali Mohammad Pur ad120606fd AK: Fix build with !USING_AK_GLOBALLY
A couple headers expected names to be in the global namespace, qualify
those names to make sure they're resolved even when the names are not
exported.
One header placed its functions in the global namespace, move those to
the AK namespace to make the concepts resolve.
2022-12-13 08:09:56 +03:30
Ali Mohammad Pur d987ddc0ee AK: Actually don't include <unistd.h> for windows in Platform.h
I got the conditions wrong last time, oops :^)
2022-12-12 17:01:16 +00:00
Arda Cinar 1cdd3bb74f AK: Add a shuffle utility function
This implements a shuffle function in AK/Random.h which works on any
container with size() and curly brace operators. It uses fisher-yates
shuffle.
2022-12-12 16:23:03 +00:00
Lucas CHOLLET 6c83bd8fd4 AK: Introduce the DerivedFrom concept 2022-12-12 16:21:39 +00:00
Ali Mohammad Pur 4aa70a07ca AK: Don't use <random> on windows for ::rand()
This is the same as the libc function, just use the libc function.
2022-12-12 15:05:48 +00:00
Ali Mohammad Pur 06816deb78 AK: Don't try to include <unistd.h> on windows for PAGE_SIZE 2022-12-12 15:05:48 +00:00
kleines Filmröllchen b81a457de5 AK: Change quicksort comments to standard // style 2022-12-12 15:03:57 +00:00
Marc Luqué 22f472249d AK: Introduce cutoff to insertion sort for Quicksort
Implement insertion sort in AK. The cutoff value 7 is a magic number
here, values [5, 15] should work well. Main idea of the cutoff is to
reduce recursion performed by quicksort to speed up sorting
of small partitions.
2022-12-12 15:03:57 +00:00
kleines Filmröllchen bbb256e8b5 AK: Introduce Indexable concept
This was dearly missing and can be used in many existing templates.
2022-12-12 15:03:57 +00:00
Ali Mohammad Pur fc805e8f03 AK: Specialise AK::is() for NNRP<T>
This is used by the Jakt runtime.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur 18bc88b806 AK: Add an identity implementation of StringView::from_string_literal()
This is required for the Jakt runtime.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur e591c604de AK: Add Optional-like value()/has_value() getters to WeakPtr 2022-12-11 20:44:54 +03:30
Ali Mohammad Pur c373c2deb0 AK: Allow constructing WeakPtr<T> using OptionalNone
The Jakt runtime requires this.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur 96b36203a2 AK: Add Optional::lazy_emplace(Callable)
This makes it possible to emplace using a given function instead of
passing constructor arguments.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur 0ed9fe3864 AK: Allow non-ascii characters to be printed
This keeps the FIXME, as well as the assertion.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur 08fc42002c AK: Format the contents of NNRP<T> if T is formattable 2022-12-11 20:44:54 +03:30
Ali Mohammad Pur ff038f306a AK: Ignore "alternative" formatting of StringView instead of crashing
Jakt implements this in a different way, but it's a noop for
StringViews anyway.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur 1cc8cdcd23 AK: Add a Error::__jakt_from_string_literal(StringView) factory function
Note that Jakt only allows StringView creation from string literals, so
none of the invariants in the class are broken by this (if used only
from within Jakt).
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur 537924a8d0 AK: Let ErrorOr<T, E> expose its result/error types
`ErrorOr<T, E>::ResultType` can now refer to `T`.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur c3b4b0e88b AK: Add support for modulo to Checked<T>
This is used by the Jakt runtime.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur cc0b970d81 AK: Allow Optional<T> to be constructed by OptionalNone()
This is needed by the Jakt runtime too.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur 12e4cd3b77 AK: Allow the user to access the variant index
The average user has no need for this, but the Jakt compiler uses this
to avoid going through the expensive ::visit() and ::get<>() APIs.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur 543890c5c9 AK: Add a fallible StringBuilder::create() factory function
This is nice, and is also used by the Jakt runtime.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur 21c2d8bd98 AK: Add a Optional::value_or_lazy_evaluated(constructor_function) API
This allows the user to avoid constructing the default value if the
optional already contains a value.
This is used by the Jakt runtime.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur cc948d06a6 AK: Add a functional-style Optional::map(mapper_function) API
This allows the user to transform the contents of the optional (if any
exists), without manually unwrapping and then rewrapping it.
This is needed by the Jakt runtime.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur 5809b4aafa AK: Let HashMap also take a ValueTraits
We were previously using Traits<V>, take that frrom the template
parameters instead.
This is needed by the Jakt runtime.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur 58252a7684 AK: Elaborate the Error constructors a bit
The old constraints were making clang mad, so express them in a less
complex way.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur 099a6bc45f AK: Give DeprecatedString::replace() a default mode
This is used in Jakt, and providing that value from Jakt's side is more
trouble than doing this.
Considering this class is bound to go away, a little
backwards-compatible API change is just fine.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur 7a17fd6d71 AK: Add a DeprecatedString::byte_at() getter
`operator[]` returns a char, this is used in Jakt.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur c547b55a00 AK: Add a Checked::unchecked_value() function
This is used in Jakt.
2022-12-11 20:44:54 +03:30
kleines Filmröllchen 16ca41ec10 AK: Add LexicalPath::is_child_of
This API checks whether this path is a child of (or the same as) another
path.
2022-12-11 16:05:23 +00:00
kleines Filmröllchen f502e24bd7 AK: Change the moved-from String state to the empty short string
The previous moved-from state was the null string. This violates both
our invariant that String is never null, and also the C++ contract that
the moved-from state must be valid but unspecified. The empty short
string state is of course valid, so it satisfies both invariants. It
also allows us to remove any extra checks for the null state.

The reason this change is made is primarily because swap() requires
moved-from objects to be reassignable (C++ allows this). Because the
move assignment of String would not check the null state, it crashed
trying to increment the data reference count (nullptr signals a
non-short string). This meant that e.g. quick_sort'ing String would
crash immediately.
2022-12-11 16:05:23 +00:00
kleines Filmröllchen ca80353efe AK: Add comparison operator
s p a c e s h i p  o p e r a t o r

Comparing UTF-8 can be done by simple byte lexicographic comparison per
definition, so we just piggy-back on StringView's high-performance
comparator.
2022-12-11 16:05:23 +00:00
Thomas Queiroz 54c12b76ed AK: Remove HashMap::ensure_capacity
This is not perfect, since the constuctor can still fail.
2022-12-10 14:29:46 +01:00
Tim Schumacher 35bcdefdf7 AK: Add Byte accessors for BigEndian and LittleEndian 2022-12-10 12:05:55 +00:00