remove unused sk_sp comparison operators

These unused comparison operators are the only users of
<functional> in SkRefCnt.h, for std::less.  <functional>
is an expensive header to compile, and SkRefCnt.h is popular,
so it helps to cut dependencies like this.

Mostly we just need to add #include <functional> in a few
places that were picking it up via SkRefCnt.h.

In SkPixmapPriv.h, it looked simpler to template the argument,
since everything was inline anyway.

Change-Id: I7c125bb26a04199847357c729a1b178256c6ef8d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/236942
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
This commit is contained in:
Mike Klein 2019-08-27 08:12:15 -05:00 committed by Skia Commit-Bot
parent e2cbd947b7
commit 334a642b20
11 changed files with 21 additions and 68 deletions

View File

@ -65,3 +65,6 @@ Milestone 78
* SkMallocPixelRef: remove MakeDirect and MakeWithProc from API. * SkMallocPixelRef: remove MakeDirect and MakeWithProc from API.
https://review.skia.org/234660 https://review.skia.org/234660
* Remove unused sk_sp comparison operators.
https://review.skia.org/236942

View File

@ -14,6 +14,7 @@
#include "include/core/SkColor.h" #include "include/core/SkColor.h"
#include "include/core/SkFlattenable.h" #include "include/core/SkFlattenable.h"
#include "include/core/SkPoint.h" #include "include/core/SkPoint.h"
#include <functional> // std::function
class SkArenaAlloc; class SkArenaAlloc;
class SkCanvas; class SkCanvas;

View File

@ -16,6 +16,7 @@
#include "include/core/SkShader.h" #include "include/core/SkShader.h"
#include "include/core/SkTileMode.h" #include "include/core/SkTileMode.h"
#include "include/gpu/GrTypes.h" #include "include/gpu/GrTypes.h"
#include <functional> // std::function
#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
#include <android/hardware_buffer.h> #include <android/hardware_buffer.h>

View File

@ -10,13 +10,12 @@
#include "include/core/SkTypes.h" #include "include/core/SkTypes.h"
#include <atomic> #include <atomic> // std::atomic, std::memory_order_*
#include <cstddef> #include <cstddef> // std::nullptr_t
#include <functional> #include <iosfwd> // std::basic_ostream
#include <iosfwd> #include <memory> // TODO: unused
#include <memory> #include <type_traits> // std::enable_if, std::is_convertible
#include <type_traits> #include <utility> // std::forward, std::swap
#include <utility>
/** \class SkRefCntBase /** \class SkRefCntBase
@ -344,49 +343,6 @@ template <typename T> inline bool operator!=(std::nullptr_t, const sk_sp<T>& b)
return static_cast<bool>(b); return static_cast<bool>(b);
} }
template <typename T, typename U> inline bool operator<(const sk_sp<T>& a, const sk_sp<U>& b) {
// Provide defined total order on sk_sp.
// http://wg21.cmeerw.net/lwg/issue1297
// http://wg21.cmeerw.net/lwg/issue1401 .
return std::less<typename std::common_type<T*, U*>::type>()(a.get(), b.get());
}
template <typename T> inline bool operator<(const sk_sp<T>& a, std::nullptr_t) {
return std::less<T*>()(a.get(), nullptr);
}
template <typename T> inline bool operator<(std::nullptr_t, const sk_sp<T>& b) {
return std::less<T*>()(nullptr, b.get());
}
template <typename T, typename U> inline bool operator<=(const sk_sp<T>& a, const sk_sp<U>& b) {
return !(b < a);
}
template <typename T> inline bool operator<=(const sk_sp<T>& a, std::nullptr_t) {
return !(nullptr < a);
}
template <typename T> inline bool operator<=(std::nullptr_t, const sk_sp<T>& b) {
return !(b < nullptr);
}
template <typename T, typename U> inline bool operator>(const sk_sp<T>& a, const sk_sp<U>& b) {
return b < a;
}
template <typename T> inline bool operator>(const sk_sp<T>& a, std::nullptr_t) {
return nullptr < a;
}
template <typename T> inline bool operator>(std::nullptr_t, const sk_sp<T>& b) {
return b < nullptr;
}
template <typename T, typename U> inline bool operator>=(const sk_sp<T>& a, const sk_sp<U>& b) {
return !(a < b);
}
template <typename T> inline bool operator>=(const sk_sp<T>& a, std::nullptr_t) {
return !(a < nullptr);
}
template <typename T> inline bool operator>=(std::nullptr_t, const sk_sp<T>& b) {
return !(nullptr < b);
}
template <typename C, typename CT, typename T> template <typename C, typename CT, typename T>
auto operator<<(std::basic_ostream<C, CT>& os, const sk_sp<T>& sp) -> decltype(os << sp.get()) { auto operator<<(std::basic_ostream<C, CT>& os, const sk_sp<T>& sp) -> decltype(os << sp.get()) {
return os << sp.get(); return os << sp.get();

View File

@ -12,6 +12,7 @@
#include "include/core/SkRefCnt.h" #include "include/core/SkRefCnt.h"
#include "include/private/SkTArray.h" #include "include/private/SkTArray.h"
#include <functional> // std::function
#include <string.h> #include <string.h>
struct SkCurve; struct SkCurve;

View File

@ -4,6 +4,7 @@
#include "include/private/SkMutex.h" #include "include/private/SkMutex.h"
#include "src/core/SkLRUCache.h" #include "src/core/SkLRUCache.h"
#include <functional> // std::function
#define PARAGRAPH_CACHE_STATS #define PARAGRAPH_CACHE_STATS

View File

@ -10,6 +10,7 @@
#include "modules/skshaper/include/SkShaper.h" #include "modules/skshaper/include/SkShaper.h"
#include "src/core/SkSpan.h" #include "src/core/SkSpan.h"
#include "src/core/SkTraceEvent.h" #include "src/core/SkTraceEvent.h"
#include <functional> // std::function
namespace skia { namespace skia {
namespace textlayout { namespace textlayout {

View File

@ -32,8 +32,9 @@ public:
* @param decode Function for decoding into a pixmap without * @param decode Function for decoding into a pixmap without
* applying the origin. * applying the origin.
*/ */
static bool Orient(const SkPixmap& dst, SkEncodedOrigin origin,
std::function<bool(const SkPixmap&)> decode) { template <typename Fn>
static bool Orient(const SkPixmap& dst, SkEncodedOrigin origin, Fn&& decode) {
SkAutoPixmapStorage storage; SkAutoPixmapStorage storage;
const SkPixmap* tmp = &dst; const SkPixmap* tmp = &dst;
if (origin != kTopLeft_SkEncodedOrigin) { if (origin != kTopLeft_SkEncodedOrigin) {

View File

@ -10,7 +10,8 @@
#include "include/core/SkTypes.h" #include "include/core/SkTypes.h"
#include "include/private/SkTHash.h" #include "include/private/SkTHash.h"
#include <vector> #include <functional> // std::hash
#include <vector> // std::vector
namespace skvm { namespace skvm {
@ -430,6 +431,7 @@ namespace skvm {
static size_t Hash(T val) { static size_t Hash(T val) {
return std::hash<T>{}(val); return std::hash<T>{}(val);
} }
// TODO: replace with SkOpts::hash()?
size_t operator()(const Instruction& inst) const { size_t operator()(const Instruction& inst) const {
return Hash((uint8_t)inst.op) return Hash((uint8_t)inst.op)
^ Hash(inst.x) ^ Hash(inst.x)

View File

@ -11,6 +11,7 @@
#include "include/core/SkColor.h" #include "include/core/SkColor.h"
#include "include/core/SkPoint.h" #include "include/core/SkPoint.h"
#include "include/core/SkRefCnt.h" #include "include/core/SkRefCnt.h"
#include <functional> // std::function
class SkMatrix; class SkMatrix;
class SkPath; class SkPath;

View File

@ -279,28 +279,13 @@ DEF_TEST(sk_sp, reporter) {
REPORTER_ASSERT(reporter, nullptr == empty); REPORTER_ASSERT(reporter, nullptr == empty);
REPORTER_ASSERT(reporter, empty == nullptr); REPORTER_ASSERT(reporter, empty == nullptr);
REPORTER_ASSERT(reporter, empty == empty); REPORTER_ASSERT(reporter, empty == empty);
REPORTER_ASSERT(reporter, nullptr <= empty);
REPORTER_ASSERT(reporter, empty <= nullptr);
REPORTER_ASSERT(reporter, empty <= empty);
REPORTER_ASSERT(reporter, nullptr >= empty);
REPORTER_ASSERT(reporter, empty >= nullptr);
REPORTER_ASSERT(reporter, empty >= empty);
} }
{ {
sk_sp<SkRefCnt> a = sk_make_sp<SkRefCnt>(); sk_sp<SkRefCnt> a = sk_make_sp<SkRefCnt>();
sk_sp<SkRefCnt> b = sk_make_sp<SkRefCnt>(); sk_sp<SkRefCnt> b = sk_make_sp<SkRefCnt>();
REPORTER_ASSERT(reporter, a != b); REPORTER_ASSERT(reporter, a != b);
REPORTER_ASSERT(reporter, (a < b) != (b < a));
REPORTER_ASSERT(reporter, (b > a) != (a > b));
REPORTER_ASSERT(reporter, (a <= b) != (b <= a));
REPORTER_ASSERT(reporter, (b >= a) != (a >= b));
REPORTER_ASSERT(reporter, a == a); REPORTER_ASSERT(reporter, a == a);
REPORTER_ASSERT(reporter, a <= a);
REPORTER_ASSERT(reporter, a >= a);
} }
// http://wg21.cmeerw.net/lwg/issue998 // http://wg21.cmeerw.net/lwg/issue998