mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 09:12:13 -05:00
AK: Optimize performance in GenericShorthands via forwarding references
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.
This commit is contained in:
parent
49fc569136
commit
36190e3baf
Notes:
github-actions[bot]
2025-01-09 08:04:50 +00:00
Author: https://github.com/izuzak Commit: https://github.com/LadybirdBrowser/ladybird/commit/36190e3baf7 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3170 Reviewed-by: https://github.com/Hendiadyoin1 Reviewed-by: https://github.com/gmta ✅
1 changed files with 19 additions and 18 deletions
|
@ -7,61 +7,62 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Platform.h>
|
#include <AK/Platform.h>
|
||||||
|
#include <AK/StdLibExtras.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
template<typename T, typename... Ts>
|
template<typename T, typename... Ts>
|
||||||
[[nodiscard]] constexpr bool first_is_one_of(T const to_compare, Ts const... valid_values)
|
[[nodiscard]] constexpr bool first_is_one_of(T&& to_compare, Ts&&... valid_values)
|
||||||
{
|
{
|
||||||
return (... || (to_compare == valid_values));
|
return (... || (forward<T>(to_compare) == forward<Ts>(valid_values)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... Ts>
|
template<typename T, typename... Ts>
|
||||||
[[nodiscard]] constexpr bool first_is_smaller_than_one_of(T const to_compare, Ts const... valid_values)
|
[[nodiscard]] constexpr bool first_is_smaller_than_one_of(T&& to_compare, Ts&&... valid_values)
|
||||||
{
|
{
|
||||||
return (... || (to_compare < valid_values));
|
return (... || (forward<T>(to_compare) < forward<Ts>(valid_values)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... Ts>
|
template<typename T, typename... Ts>
|
||||||
[[nodiscard]] constexpr bool first_is_smaller_or_equal_than_one_of(T const to_compare, Ts const... valid_values)
|
[[nodiscard]] constexpr bool first_is_smaller_or_equal_than_one_of(T&& to_compare, Ts&&... valid_values)
|
||||||
{
|
{
|
||||||
return (... || (to_compare <= valid_values));
|
return (... || (forward<T>(to_compare) <= forward<Ts>(valid_values)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... Ts>
|
template<typename T, typename... Ts>
|
||||||
[[nodiscard]] constexpr bool first_is_larger_than_one_of(T const to_compare, Ts const... valid_values)
|
[[nodiscard]] constexpr bool first_is_larger_than_one_of(T&& to_compare, Ts&&... valid_values)
|
||||||
{
|
{
|
||||||
return (... || (to_compare > valid_values));
|
return (... || (forward<T>(to_compare) > forward<Ts>(valid_values)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... Ts>
|
template<typename T, typename... Ts>
|
||||||
[[nodiscard]] constexpr bool first_is_larger_or_equal_than_one_of(T const to_compare, Ts const... valid_values)
|
[[nodiscard]] constexpr bool first_is_larger_or_equal_than_one_of(T&& to_compare, Ts&&... valid_values)
|
||||||
{
|
{
|
||||||
return (... || (to_compare >= valid_values));
|
return (... || (forward<T>(to_compare) >= forward<Ts>(valid_values)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... Ts>
|
template<typename T, typename... Ts>
|
||||||
[[nodiscard]] constexpr bool first_is_smaller_than_all_of(T const to_compare, Ts const... valid_values)
|
[[nodiscard]] constexpr bool first_is_smaller_than_all_of(T&& to_compare, Ts&&... valid_values)
|
||||||
{
|
{
|
||||||
return (... && (to_compare < valid_values));
|
return (... && (forward<T>(to_compare) < forward<Ts>(valid_values)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... Ts>
|
template<typename T, typename... Ts>
|
||||||
[[nodiscard]] constexpr bool first_is_smaller_or_equal_than_all_of(T const to_compare, Ts const... valid_values)
|
[[nodiscard]] constexpr bool first_is_smaller_or_equal_than_all_of(T&& to_compare, Ts&&... valid_values)
|
||||||
{
|
{
|
||||||
return (... && (to_compare <= valid_values));
|
return (... && (forward<T>(to_compare) <= forward<Ts>(valid_values)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... Ts>
|
template<typename T, typename... Ts>
|
||||||
[[nodiscard]] constexpr bool first_is_larger_than_all_of(T const to_compare, Ts const... valid_values)
|
[[nodiscard]] constexpr bool first_is_larger_than_all_of(T&& to_compare, Ts&&... valid_values)
|
||||||
{
|
{
|
||||||
return (... && (to_compare > valid_values));
|
return (... && (forward<T>(to_compare) > forward<Ts>(valid_values)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... Ts>
|
template<typename T, typename... Ts>
|
||||||
[[nodiscard]] constexpr bool first_is_larger_or_equal_than_all_of(T const to_compare, Ts const... valid_values)
|
[[nodiscard]] constexpr bool first_is_larger_or_equal_than_all_of(T&& to_compare, Ts&&... valid_values)
|
||||||
{
|
{
|
||||||
return (... && (to_compare >= valid_values));
|
return (... && (forward<T>(to_compare) >= forward<Ts>(valid_values)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue