Skip to content

Commit

Permalink
Reduce string duplication in enum debug output operators.
Browse files Browse the repository at this point in the history
Bloaty says it saved 10 kB in Debug build of MagnumGL:

     VM SIZE                     FILE SIZE
 --------------               --------------
  [ = ]       0 .debug_info   +1.59Ki  +0.0%
  +0.4% +1.50Ki .text         +1.50Ki  +0.4%
  [ = ]       0 .debug_str       +409  +0.0%
  [ = ]       0 .debug_line      +276  +0.1%
  [ = ]       0 .debug_abbrev     +20  +0.0%
 -28.6%      -2 [LOAD [RX]]        -2 -28.6%
  [ = ]       0 [Unmapped]    -4.28Ki -41.0%
 -22.7% -9.23Ki .rodata       -9.23Ki -22.7%
  -0.8% -7.73Ki TOTAL         -9.73Ki  -0.1%

And 4 kB in Release:

     VM SIZE                  FILE SIZE
 --------------            --------------
  +1.1% +3.44Ki .text      +3.44Ki  +1.1%
  +1.7% +1.39Ki .eh_frame  +1.39Ki  +1.7%
  [ = ]       0 [Unmapped]    +656   +51%
 -25.5% -9.47Ki .rodata    -9.47Ki -25.5%
  -0.7% -4.64Ki TOTAL      -4.00Ki  -0.4%

That's not negative, so I guess that's good. This change is of course
more significant in the context of a minimal WebGL build, where the exe
can be as little as 50 kB -- there 4 kB is almost 10% of the size.
  • Loading branch information
mosra committed Nov 11, 2019
1 parent f4e409b commit 98232f3
Show file tree
Hide file tree
Showing 39 changed files with 354 additions and 196 deletions.
12 changes: 8 additions & 4 deletions src/Magnum/Animation/Interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ namespace Magnum { namespace Animation {

#ifndef DOXYGEN_GENERATING_OUTPUT
Debug& operator<<(Debug& debug, const Interpolation value) {
debug << "Animation::Interpolation" << Debug::nospace;

switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case Interpolation::value: return debug << "Animation::Interpolation::" #value;
#define _c(value) case Interpolation::value: return debug << "::" #value;
_c(Constant)
_c(Linear)
_c(Spline)
Expand All @@ -43,21 +45,23 @@ Debug& operator<<(Debug& debug, const Interpolation value) {
/* LCOV_EXCL_STOP */
}

return debug << "Animation::Interpolation(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
}

Debug& operator<<(Debug& debug, const Extrapolation value) {
debug << "Animation::Extrapolation" << Debug::nospace;

switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case Extrapolation::value: return debug << "Animation::Extrapolation::" #value;
#define _c(value) case Extrapolation::value: return debug << "::" #value;
_c(DefaultConstructed)
_c(Constant)
_c(Extrapolated)
#undef _c
/* LCOV_EXCL_STOP */
}

return debug << "Animation::Extrapolation(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
}
#endif

Expand Down
6 changes: 4 additions & 2 deletions src/Magnum/Animation/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@
namespace Magnum { namespace Animation {

Debug& operator<<(Debug& debug, const State value) {
debug << "Animation::State" << Debug::nospace;

switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case State::value: return debug << "Animation::State::" #value;
#define _c(value) case State::value: return debug << "::" #value;
_c(Stopped)
_c(Playing)
_c(Paused)
#undef _c
/* LCOV_EXCL_STOP */
}

return debug << "Animation::State(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
}

/* On non-MinGW Windows the instantiations are already marked with extern
Expand Down
6 changes: 4 additions & 2 deletions src/Magnum/Audio/AbstractImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,17 @@ Containers::Array<char> AbstractImporter::data() {
}

Debug& operator<<(Debug& debug, const AbstractImporter::Feature value) {
debug << "Audio::AbstractImporter::Feature" << Debug::nospace;

switch(value) {
/* LCOV_EXCL_START */
#define _c(v) case AbstractImporter::Feature::v: return debug << "Audio::AbstractImporter::Feature::" #v;
#define _c(v) case AbstractImporter::Feature::v: return debug << "::" #v;
_c(OpenData)
#undef _c
/* LCOV_EXCL_STOP */
}

return debug << "Audio::AbstractImporter::Feature(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
}

Debug& operator<<(Debug& debug, const AbstractImporter::Features value) {
Expand Down
6 changes: 4 additions & 2 deletions src/Magnum/Audio/BufferFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
namespace Magnum { namespace Audio {

Debug& operator<<(Debug& debug, const BufferFormat value) {
debug << "Audio::BufferFormat" << Debug::nospace;

switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case BufferFormat::value: return debug << "Audio::BufferFormat::" #value;
#define _c(value) case BufferFormat::value: return debug << "::" #value;
_c(Mono8)
_c(Mono16)
_c(Stereo8)
Expand Down Expand Up @@ -73,7 +75,7 @@ Debug& operator<<(Debug& debug, const BufferFormat value) {
/* LCOV_EXCL_STOP */
}

return debug << "Audio::BufferFormat(" << Debug::nospace << reinterpret_cast<void*>(ALenum(value)) << Debug::nospace << ")";
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(ALenum(value)) << Debug::nospace << ")";
}

}}
6 changes: 4 additions & 2 deletions src/Magnum/Audio/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ Containers::ArrayView<const Extension> Extension::extensions() {
}

Debug& operator<<(Debug& debug, const Context::HrtfStatus value) {
debug << "Audio::Context::HrtfStatus" << Debug::nospace;

switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case Context::HrtfStatus::value: return debug << "Audio::Context::HrtfStatus::" #value;
#define _c(value) case Context::HrtfStatus::value: return debug << "::" #value;
_c(Disabled)
_c(Enabled)
_c(Denied)
Expand All @@ -84,7 +86,7 @@ Debug& operator<<(Debug& debug, const Context::HrtfStatus value) {
/* LCOV_EXCL_STOP */
}

return debug << "Audio::Context::HrtfStatus(" << Debug::nospace << reinterpret_cast<void*>(ALenum(value)) << Debug::nospace << ")";
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(ALenum(value)) << Debug::nospace << ")";
}

namespace {
Expand Down
12 changes: 8 additions & 4 deletions src/Magnum/Audio/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
namespace Magnum { namespace Audio {

Debug& operator<<(Debug& debug, const Renderer::Error value) {
debug << "Audio::Renderer::Error" << Debug::nospace;

switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case Renderer::Error::value: return debug << "Audio::Renderer::Error::" #value;
#define _c(value) case Renderer::Error::value: return debug << "::" #value;
_c(NoError)
_c(InvalidName)
_c(InvalidEnum)
Expand All @@ -43,13 +45,15 @@ Debug& operator<<(Debug& debug, const Renderer::Error value) {
/* LCOV_EXCL_STOP */
}

return debug << "Audio::Renderer::Error(" << Debug::nospace << reinterpret_cast<void*>(ALenum(value)) << Debug::nospace << ")";
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(ALenum(value)) << Debug::nospace << ")";
}

Debug& operator<<(Debug& debug, const Renderer::DistanceModel value) {
debug << "Audio::Renderer::DistanceModel" << Debug::nospace;

switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case Renderer::DistanceModel::value: return debug << "Audio::Renderer::DistanceModel::" #value;
#define _c(value) case Renderer::DistanceModel::value: return debug << "::" #value;
_c(None)
_c(Inverse)
_c(InverseClamped)
Expand All @@ -61,7 +65,7 @@ Debug& operator<<(Debug& debug, const Renderer::DistanceModel value) {
/* LCOV_EXCL_STOP */
}

return debug << "Audio::Renderer::DistanceModel(" << Debug::nospace << reinterpret_cast<void*>(ALenum(value)) << Debug::nospace << ")";
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(ALenum(value)) << Debug::nospace << ")";
}

}}
12 changes: 8 additions & 4 deletions src/Magnum/Audio/Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ void Source::rewind(const std::vector<std::reference_wrapper<Source>>& sources)
}

Debug& operator<<(Debug& debug, const Source::State value) {
debug << "Audio::Source::State" << Debug::nospace;

switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case Source::State::value: return debug << "Audio::Source::State::" #value;
#define _c(value) case Source::State::value: return debug << "::" #value;
_c(Initial)
_c(Playing)
_c(Paused)
Expand All @@ -137,21 +139,23 @@ Debug& operator<<(Debug& debug, const Source::State value) {
/* LCOV_EXCL_STOP */
}

return debug << "Audio::Source::State(" << Debug::nospace << reinterpret_cast<void*>(ALint(value)) << Debug::nospace << ")";
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(ALint(value)) << Debug::nospace << ")";
}

Debug& operator<<(Debug& debug, const Source::Type value) {
debug << "Audio::Source::Type" << Debug::nospace;

switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case Source::Type::value: return debug << "Audio::Source::Type::" #value;
#define _c(value) case Source::Type::value: return debug << "::" #value;
_c(Undetermined)
_c(Static)
_c(Streaming)
#undef _c
/* LCOV_EXCL_STOP */
}

return debug << "Audio::Source::Type(" << Debug::nospace << reinterpret_cast<void*>(ALint(value)) << Debug::nospace << ")";
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(ALint(value)) << Debug::nospace << ")";
}

}}
6 changes: 4 additions & 2 deletions src/Magnum/FileCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@
namespace Magnum {

Debug& operator<<(Debug& debug, const InputFileCallbackPolicy value) {
debug << "InputFileCallbackPolicy" << Debug::nospace;

switch(value) {
/* LCOV_EXCL_START */
#define _c(v) case InputFileCallbackPolicy::v: return debug << "InputFileCallbackPolicy::" #v;
#define _c(v) case InputFileCallbackPolicy::v: return debug << "::" #v;
_c(LoadTemporary)
_c(LoadPermanent)
_c(Close)
#undef _c
/* LCOV_EXCL_STOP */
}

return debug << "InputFileCallbackPolicy(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
}

}
Loading

0 comments on commit 98232f3

Please sign in to comment.