Commit graph

1619 commits

Author SHA1 Message Date
Andreas Kling 834b6508d7 AK: Remove StringBuilder::appendf()
All users have been converted to using AK::Format via appendff().
2021-05-07 21:12:09 +02:00
Valtteri Koskivuori 1069979ddf AK: Implement Span::starts_with()
Useful for checking for contents at the start of a span.
2021-05-07 11:46:53 +01:00
Ali Mohammad Pur da68c4580c AK: Make Checked<T> check for division overflow as well
Signed integer overflow can occur with division when the RHS is -1,
as the negative values' range is one larger than the positives.
2021-05-07 09:26:11 +02:00
Brian Gianforcaro 67322b0702 Tests: Move AK tests to Tests/AK 2021-05-06 17:54:28 +02:00
AnotherTest ba6c9423b8 AK: Implement printf fraction length specification for strings
This adds support for '%.20s' and friends :^)
2021-05-06 15:20:31 +01:00
Ali Mohammad Pur a51113c58e AK: Add a Variant<Ts...> implementation
Also adds an AK::Empty struct, because 'empty' variants are useful, but
this implementation leaves that to the user (i.e. a variant cannot
actually be empty, but it can contain an instance of Empty - i.e. a
byte).
Note that this is more of a constrained Any type, but they basically do
the same things anyway :^)
2021-05-05 19:02:51 +02:00
Ali Mohammad Pur ab03c6fadf AK: Export integer_sequence_generate_array() 2021-05-05 19:02:51 +02:00
Ali Mohammad Pur b361793ad8 AK: Add min() and max() methods to Array<T, N>
...That are only defined when min() and max() are defined on the
elements.
2021-05-05 19:02:51 +02:00
Ali Mohammad Pur d288f6654e AK: Make LEB128 capable of reading into any type
And not just ssize_t/size_t.
This is useful in cases where the output size is supposed to be larger
than size_t.
2021-05-04 22:33:35 +02:00
Ali Mohammad Pur 48260b5054 AK: Move the LEB128 logic to AK and make it usable with InputStream 2021-05-04 22:33:35 +02:00
Ali Mohammad Pur 415fd4d2ec AK: Make DistinctNumeric constexpr-capable 2021-05-04 21:32:15 +02:00
Gunnar Beutner 56ee4a1af2 AK: Silence -Wmaybe-uninitialized warning
Adding -fno-semantic-interposition to the GCC command
line caused this new warning.

I don't see how output.data() could be uninitialized here. Also,
commenting out the ensure_capacity() call for the Vector
also gets rid of this warning.
2021-05-03 08:42:39 +02:00
Tobias Christiansen 4016e04061 AK: Move bijective-base-conversion into AK/String
This allows everybody to create a String version of their number
in a arbitrary bijective base. Bijective base meaning that the mapping
doesn't have a 0. In the usual mapping to the alphabet the follower
after 'Z' is 'AA'.
The mapping using the (uppercase) alphabet is used as a standard but
can be overridden specifying 'base' and 'map'.

The code was directly yanked from the Spreadsheet.
2021-05-01 01:19:40 +02:00
Gunnar Beutner ad688ffc73 AK: Make dbgln log the thread ID
This makes debugging multi-threaded programs easier.
2021-04-29 23:12:05 +02:00
Andreas Kling 3d4afe7614 Everywhere: "indexes" => "indices"
I've wasted a silly amount of time in the past fretting over which
of these words to use. Let's just choose one and use it everywhere. :^)
2021-04-29 22:23:52 +02:00
Andreas Kling 7ae7170d61 Everywhere: "file name" => "filename" 2021-04-29 22:16:18 +02:00
Sahan Fernando c3cf739b94 AK: Make AK::Vector expose allocation failures in API 2021-04-29 09:02:58 +02:00
Linus Groh 649d2faeab Everywhere: Use "the SerenityOS developers." in copyright headers
We had some inconsistencies before:

- Sometimes "The", sometimes "the"
- Sometimes trailing ".", sometimes no trailing "."

I picked the most common one (lowecase "the", trailing ".") and applied
it to all copyright headers.

By using the exact same string everywhere we can ensure nothing gets
missed during a global search (and replace), and that these
inconsistencies are not spread any further (as copyright headers are
commonly copied to new files).
2021-04-29 00:59:26 +02:00
Mart G c9f3cc6dcc AK: Guarantee a maximum stack depth for dual_pivot_quick_sort
When the two chosen pivots happen to be the smallest and largest
elements of the array, three partitions will be created, two of
size 0 and one of size n-2. If this happens on each recursive call
to dual_pivot_quick_sort, the stack depth will reach approximately n/2.

To avoid the stack from deepening, iteration can be used for the
largest of the three partitions. This ensures the stack depth
will only increase for partitions of size n/2 or smaller, which
results in a maximum stack depth of log(n).
2021-04-28 21:38:48 +02:00
Mart G 67b0d04315 AK: Change pivot selection of dual_pivot_quick_sort
Picking the first and last elements as pivots makes it so that
a sorted array is the worst-case input for the algorithm.

This change instead picks pivots at approximately 1/3 and 2/3 in
the array. This results in desired performance for sorted arrays.

Of course this only changes which inputs result in worst-case
performance, but hopefully those inputs occur less frequently than
already sorted arrays.
2021-04-28 21:38:48 +02:00
Jean-Baptiste Boric 7d84f09e7e Userland: Move non-standard math constants from math.h 2021-04-27 23:06:16 +02:00
Gunnar Beutner f57c57966b AK: Fix argument type for JsonArray::at and JsonArray::operator[] 2021-04-26 17:13:55 +02:00
Linus Groh dbe72fd962 Everywhere: Remove empty line after function body opening curly brace 2021-04-25 20:20:00 +02:00
sin-ack bb096429ad Tests: Remove 4chan catalog JSON from tree
According to kling, it was "an early stress test for the JSON decoder"
and can be removed now.
2021-04-25 10:15:15 +02:00
Brian Gianforcaro 87724b3d09 AK: Add default constructor to SourceLocation 2021-04-25 09:38:27 +02:00
Andrew Kaster 35c0a6c54d AK+Userland: Move AK/TestSuite.h into LibTest and rework Tests' CMake
As many macros as possible are moved to Macros.h, while the
macros to create a test case are moved to TestCase.h. TestCase is now
the only user-facing header for creating a test case. TestSuite and its
helpers have moved into a .cpp file. Instead of requiring a TEST_MAIN
macro to be instantiated into the test file, a TestMain.cpp file is
provided instead that will be linked against each test. This has the
side effect that, if we wanted to have test cases split across multiple
files, it's as simple as adding them all to the same executable.

The test main should be portable to kernel mode as well, so if
there's a set of tests that should be run in self-test mode in kernel
space, we can accomodate that.

A new serenity_test CMake function streamlines adding a new test with
arguments for the test source file, subdirectory under /usr/Tests to
install the test application and an optional list of libraries to link
against the test application. To accomodate future test where the
provided TestMain.cpp is not suitable (e.g. test-js), a CUSTOM_MAIN
parameter can be passed to the function to not link against the
boilerplate main function.
2021-04-25 09:36:49 +02:00
Andrew Kaster 89ee38fe5c Tests: Add environment variable for tests only
This is useful for CI where we don't want to spend a minute and a half
benchmarking Vector::append, and we don't have a good way to pass
test-specific arguments yet. :)
2021-04-25 09:36:49 +02:00
Brian Gianforcaro 7a73f11005 LibCpp: Convert ScopeLogger to use AK:SourceLocation
Utilize AK::SourceLocation to get function information into
the scope logger, instead of relying on pre-processor macros.
2021-04-25 09:32:03 +02:00
Brian Gianforcaro 357a13b404 AK: Add a AK::Formatter implementation for AK::SourceLocation 2021-04-25 09:32:03 +02:00
Brian Gianforcaro 0ad29bc3c9 AK: Add SourceLocation support
C++20 added std::source_location, which lets you capture the
callers __FILE__ / __LINE__ / __FUNCTION__ etc as a default
argument to functions.
See: https://en.cppreference.com/w/cpp/utility/source_location

During a bug investigation @ADKaster suggested we could use this
to make the LOCK_DEBUG feature of the kernel more user friendly
and allow it to automatically instrument all call sites.

We then implemented / tested it over discord. :^)

Co-Authored-by: Andrew Kaster <andrewdkaster@gmail.com>
2021-04-24 20:33:00 +02:00
Andreas Kling b91c49364d AK: Rename adopt() to adopt_ref()
This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
2021-04-23 16:46:57 +02:00
Idan Horowitz f90c224fc5 Revert "AK: Remove virtual destructors from non-virtual classes"
This reverts commit 4378d36f67.
2021-04-23 10:26:14 +02:00
Lenny Maiorani 4378d36f67 AK: Remove virtual destructors from non-virtual classes
Problem:
- Some classes have `virtual` destructors despite not having any
  virtual functions. This causes the classes to have a v-table and
  perform extra jumps at destruction time when there is no need.

Solution:
- Remove `virtual` keyword from destructors where there are no other
  virtual functions.
- Remove the destructor completely when the default destructor can be
  used.
2021-04-23 08:28:25 +02:00
Idan Horowitz 1c512a702a AK+Userland: Use idan.horowitz@serenityos.org for my copyright headers 2021-04-22 22:42:38 +02:00
Ali Mohammad Pur 38418fdfdf AK+Userland: Use mpfard@serenityos.org for my copyright headers 2021-04-22 22:19:09 +02:00
Brian Gianforcaro dc0fc16981 Everywhere: Use bgianf@serenityos.org for my copyright attribution 2021-04-22 21:15:54 +02:00
Lenny Maiorani 254e010c75 AK/GenericLexer: constexpr where possible
Problem:
- Much of the `GenericLexer` can be `constexpr`, but is not.

Solution:
- Make it `constexpr` and de-duplicate code.
- Extend some of `StringView` with `constexpr` to support.
- Add tests to ensure `constexpr` behavior.

Note:
- Construction of `StringView` from pointer and length is not
  `constexpr`-compatible at the moment because the VERIFY cannot be,
  yet.
2021-04-22 20:27:21 +02:00
Brian Gianforcaro 1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Ali Mohammad Pur ba261aba72 AK: Reenable the IntrusiveList<...NonnullRefPtr, ...> tests 2021-04-22 00:20:51 +02:00
Ali Mohammad Pur 88b97f5367 AK: Make IntrusiveList work with NonnullRefPtr's 2021-04-22 00:20:51 +02:00
Andreas Kling edf0b14e23 AK: Remove String::format()
There are no more clients of this function, everyone has been converted
to String::formatted().
2021-04-21 23:49:03 +02:00
Andreas Kling f8dfc74f8b AK: Decorate most of ByteBuffer with [[nodiscard]] 2021-04-21 23:49:01 +02:00
Andreas Kling b0ccb5ba9d AK: Decorate most of String's API's with [[nodiscard]] 2021-04-21 23:49:01 +02:00
Lenny Maiorani e117756d9f AK/Format: Compute TypeErasedParameter type and size at compile-time
Problem:
- Type and size information is known at compile-time, but computations
  are being performed using run-time parameters.

Solution:
- Move function arguments to be template arguments.
- Convert to `consteval` where possible.
- Decorate functions with `constexpr` which are used in both run-time
  and compile-time contexts.
2021-04-21 23:26:16 +02:00
Lenny Maiorani 730fbfb31e AK/Format: Fix incorrectly non-inlined variable templates
Problem:
- Global variables (and variable templates) defined in header files
  need to be decorated `inline` to avoid multiple definition issues.

Solution:
- Put back the `inline` keyword which was erroneously removed.
2021-04-21 21:15:35 +02:00
Lenny Maiorani ece8aeaaf4 Everywhere: Remove redundant inline keyword with constexpr
Problem:
- `constexpr` functions are additionally decorated with `inline`
  keyword. This is redundant since `constexpr` implies `inline`.

Solution:
- Remove redundancies.
2021-04-21 20:49:49 +02:00
Brian Gianforcaro f1d832e5ea AK: Add unit tests to verify AK::InstrusiveList<T> holding RefPtr<T>
Validate that the refcounting works as expected, and continues to work.
2021-04-21 19:31:49 +02:00
Brian Gianforcaro 93e5ba2347 AK: Fix IntrusvieList::take_first/last() actually compile with RefPtr<T>
PR #6376 made IntrusiveList capable of holding RefPtr<T>, etc. however
there was a latent bug where take_first() / take_last() would fail to
compile because they weren't being converted to their container type.
2021-04-21 19:31:49 +02:00
Brian Gianforcaro 0e63a7255e AK: Add some initial unit tests for AK::IntrusiveList 2021-04-21 19:31:49 +02:00
Timothy Flynn 55b7b8e930 AK+Meta: Add a debug option for LibSQL 2021-04-20 18:28:34 +02:00