<ostream> -> <iosfwd>

<ostream> is one of the more expensive headers to include
and that's amplified by SkRefCnt.h's popularity.

We've been including <ostream> for sk_sp's operator<<.  That's only
used by Chromium and while we could just sprinkle in a bunch of .get()
calls and remove operator<<, when I started going through and actually
doing that I got the feeling I was making things pointlessly harder to
read and write, and wanted to find a way to make it actually work.

My next instinct was to template it without mentioning ostreams,

    template <typename OS, typename T>
    auto operator<<(OS& os, const sk_sp<T>& sp) -> decltype(os << sp.get()) {
        return os << sp.get();
    }

but that makes this operator<< ambiguous with some other templated operator<<
in GTest.  They got in first, so they win...

So ultimately, switch <ostream> to <iosfwd>.   Anyone using our
operator<<() presumably has <ostream> included already, and the #include
cost for <iosfwd> is small enough that I don't think we'll mind keeping
this around indefinitely.

To repro, look at before/after of -ftime-trace:

    ~/chromium/src/third_party/llvm-build/Release+Asserts/bin/clang++ -I. -Os -c src/core/SkCanvas.cpp -ftime-trace

I have tested locally that Chromium builds with this change.

Change-Id: I9decc2e65b5cc8fd07d8106a5eff81901aedd7d5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/237190
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Mike Klein 2019-08-26 11:24:50 -05:00 committed by Skia Commit-Bot
parent e384df4f5e
commit 48e08aa973
4 changed files with 7 additions and 1 deletions

View File

@ -13,8 +13,8 @@
#include <atomic> #include <atomic>
#include <cstddef> #include <cstddef>
#include <functional> #include <functional>
#include <iosfwd>
#include <memory> #include <memory>
#include <ostream>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>

View File

@ -19,6 +19,7 @@
#include "tools/ToolUtils.h" #include "tools/ToolUtils.h"
#include <cmath> #include <cmath>
#include <string>
#include <tuple> #include <tuple>
#include <vector> #include <vector>

View File

@ -5,6 +5,7 @@
#include "include/core/SkFontStyle.h" #include "include/core/SkFontStyle.h"
#include "modules/skparagraph/include/DartTypes.h" #include "modules/skparagraph/include/DartTypes.h"
#include "modules/skparagraph/include/TextStyle.h" #include "modules/skparagraph/include/TextStyle.h"
#include <string> // std::u16string
namespace skia { namespace skia {
namespace textlayout { namespace textlayout {

View File

@ -15,6 +15,10 @@
#if defined(SKVM_JIT) #if defined(SKVM_JIT)
#include <sys/mman.h> #include <sys/mman.h>
#endif #endif
#if defined(SKVM_PERF_DUMPS)
#include <stdio.h>
#include <time.h>
#endif
namespace skvm { namespace skvm {