Skip to content

Minimize heavy STL headers in GoogleTest and GoogleMock public headers#4947

Open
unseen2004 wants to merge 1 commit intogoogle:mainfrom
unseen2004:main
Open

Minimize heavy STL headers in GoogleTest and GoogleMock public headers#4947
unseen2004 wants to merge 1 commit intogoogle:mainfrom
unseen2004:main

Conversation

@unseen2004
Copy link
Copy Markdown

Description:
This PR addresses Issue #4943 (#4943) by minimizing the inclusion of heavy standard library headers like
and in public GoogleTest and GoogleMock headers. This should significantly improve compilation times for projects with many test
translation units.

Key Changes:

  • Introduced internal::StreamTo Helpers: Added a series of StreamTo overloads in namespace internal to handle the streaming of common types (built-ins,
    strings, etc.) without requiring the full definition of std::ostream.
  • Header Optimization: Swapped and for in the following public headers:
    • gtest/gtest.h
    • gtest/gtest-printers.h
    • gtest/gtest-matchers.h
    • gmock/gmock-matchers.h
    • gmock/gmock-spec-builders.h
    • (and several internal headers)
  • Refactored StringMatchResultListener: Moved the std::stringstream member of StringMatchResultListener into the implementation file
    (gmock-matchers.cc) using a std::unique_ptrstd::ostream, hiding the heavy dependency from the public header.
  • Code Migration: Moved several non-template PrintTo and StreamTo implementations from headers to .cc files.
  • Enhanced API: Made MatchResultListener::stream() const to facilitate better access in const contexts.

Verification:

  • A full build of the entire project (googletest and googlemock) was completed successfully.
  • All existing tests were built and linked correctly with the new optimizations.

Fixes #4943

This change reduces compilation time by replacing heavy headers like
<ostream> and <sstream> with <iosfwd> in public headers.

Key changes:
- Introduced internal::StreamTo helper functions to handle streaming
  common types without requiring <ostream> in headers.
- Updated GoogleTest and GoogleMock public headers to use <iosfwd>.
- Refactored StringMatchResultListener to hide its std::stringstream
  implementation in gmock-matchers.cc.
- Moved non-template PrintTo overloads to .cc files.

Fixes google#4943.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR]: Improve compilation time by minimizing inclusions of <ostream>, <string>, and <vector>

1 participant