We currently have a fair amount of code of the form:
if (is<Child>(parent)) {
auto& child = static_cast<Child&>(parent);
if (child.foo()) {
}
}
This new cast allows us to instead write code of the form:
if (auto* child = as_if<Child>(parent); child && child->foo()) {
}
N.B. The name "as_if" was chosen because we are considering renaming
verify_cast to "as".
Co-authored-by: Tim Ledbetter <tim.ledbetter@ladybird.org>
This separates the StringBuilder constructor into 2 constructors. This
essentially allows forming code of the following pattern:
StringBuilder foo() { return {}; }
Otherwise, we would get the following compiler error:
chosen constructor is explicit in copy-initialization
Due to the explicitness of the StringBuilder constructor.
This is required for an upcoming update to ICU 76, where we use our
StringBuilder in templated ICU code.
Functions in AK/GenericShorthands used pass-by-value which results in
copying values when calling those functions. This could be expensive
for complex types. To optimize performance, we switch the functions to
use forwarding references.
if (size <= 1)
return;
This means that size is at the very minimum 2,
and pivot_point at the very minimum equals 1 as size / 2;
The condition if (pivot_point) can never be false.
Done by forward declaring the required functions and defining the needed
constants. The defines shouldn't collide as they are from memoryapi.h.
This is done to avoid including windows.h.
Previously, it ignored 'start', sorting from the array's
beginning. This caused unintended changes and slower
performance. Fix ensures sorting stays within 'start'
and 'end' indices only.
Lines like these were getting a warning to simplify the expanded
boolean expression from `!(a || b)` to `(a && b)`, but since the
`!(...)` is part of the macro, that is never going to happen.
The refactor in the previous commit was storing a reference to a stack
allocated `Infrastructure::Request::BodyType` which was then immediately
freed. To fix this, we can store the `Infrastructure::Request::BodyType`
in a variable beforehand, so it becomes safe to reference.
C++ will jovially select the implicit conversion operator, even if it's
complete bogus, such as for unknown-size types or non-destructible
types. Therefore, all such conversions (which incur a copy) must
(unfortunately) be explicit so that non-copyable types continue to work.
NOTE: We make an exception for trivially copyable types, since they
are, well, trivially copyable.
Co-authored-by: kleines Filmröllchen <filmroellchen@serenityos.org>
This makes them trivially copyable/movable, silencing
> "parameter is copied for each invocation"
warnings on `Optional<T&>`, which are unnecessairy,
since `Optional<T&>` is just a trivially copyable pointer.
This creates a slight change in behaviour when moving out of an
`Optional<T&>`, since the moved-from optional no longer gets cleared.
Moved-from values should be considered to be in an undefined state,
and if clearing a moved-from `Optional<T&>` is desired, you should be
using `Optional<T&>::release_value()` instead.
```
VERIFICATION FAILED: !_temporary_result.is_error()
```
is not really a helpful error message.
When we are including `AK/Format.h`, which is most of the time,
we can easily print a much more useful error message:
```
UNEXPECTED ERROR: Cannot allocate memory (errno=12)
```
There was an existing check to ensure that `U` was an lvalue reference,
but when this check fails, overload resolution will just move right on
to the copy asignment operator, which will cause the temporary to be
assigned anyway.
Disallowing `Optional<T&>`s to be created from temporaries entirely
would be undesired, since existing code has valid reasons for creating
`Optional<T&>`s from temporaries, such as for function call arguments.
This fix explicitly deletes the `Optional::operator=(U&&)` operator,
so overload resolution stops.