From 7f9f37ce5afbb9409968e1760c0ab0b4538f9562 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Mon, 4 Oct 2021 12:35:32 +1100 Subject: [PATCH] Have examples use WUFFS_CONFIG__STATIC_FUNCTIONS Compile time: $ time ./build-example.sh Before: user 1m15.750s After: user 0m50.343s Binary size (excluding the statically linked example-toy-genlib): $ ls -l gen/bin/example-* | awk '{print $5 " " $9}' Before: 212624 gen/bin/example-cbor-to-json 284192 gen/bin/example-convert-to-nia 344744 gen/bin/example-crc32 184304 gen/bin/example-gifplayer 324952 gen/bin/example-imageviewer 209632 gen/bin/example-json-to-cbor 241432 gen/bin/example-jsonfindptrs 196320 gen/bin/example-jsonptr 309768 gen/bin/example-sdl-imageviewer 200704 gen/bin/example-zcat After: 85280 gen/bin/example-cbor-to-json 242216 gen/bin/example-convert-to-nia 344744 gen/bin/example-crc32 53328 gen/bin/example-gifplayer 282840 gen/bin/example-imageviewer 95152 gen/bin/example-json-to-cbor 122720 gen/bin/example-jsonfindptrs 60448 gen/bin/example-jsonptr 267672 gen/bin/example-sdl-imageviewer 64792 gen/bin/example-zcat Before total: 2508672 After total: 1619192 --- example/cbor-to-json/cbor-to-json.cc | 10 ++++++++++ example/convert-to-nia/convert-to-nia.c | 10 ++++++++++ example/crc32/crc32.cc | 10 +++++++--- example/gifplayer/gifplayer.c | 10 ++++++++++ example/imageviewer/imageviewer.cc | 10 ++++++++++ example/json-to-cbor/json-to-cbor.cc | 10 ++++++++++ example/jsonfindptrs/jsonfindptrs.cc | 10 ++++++++++ example/jsonptr/jsonptr.cc | 10 ++++++++++ example/sdl-imageviewer/sdl-imageviewer.cc | 10 ++++++++++ example/zcat/zcat.c | 10 ++++++++++ internal/cgen/base/fundamental-public.h | 9 ++++++--- release/c/wuffs-unsupported-snapshot.c | 9 ++++++--- 12 files changed, 109 insertions(+), 9 deletions(-) diff --git a/example/cbor-to-json/cbor-to-json.cc b/example/cbor-to-json/cbor-to-json.cc index 4816c902..e23b8cdc 100644 --- a/example/cbor-to-json/cbor-to-json.cc +++ b/example/cbor-to-json/cbor-to-json.cc @@ -46,6 +46,16 @@ for a C++ compiler $CXX, such as clang++ or g++. // compiling it. #define WUFFS_IMPLEMENTATION +// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when +// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs' +// functions have static storage. +// +// This can help the compiler ignore or discard unused code, which can produce +// faster compiles and smaller binaries. Other motivations are discussed in the +// "ALLOW STATIC IMPLEMENTATION" section of +// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt +#define WUFFS_CONFIG__STATIC_FUNCTIONS + // Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of // release/c/etc.c choose which parts of Wuffs to build. That file contains the // entire Wuffs standard library, implementing a variety of codecs and file diff --git a/example/convert-to-nia/convert-to-nia.c b/example/convert-to-nia/convert-to-nia.c index fe349aff..c05d69f2 100644 --- a/example/convert-to-nia/convert-to-nia.c +++ b/example/convert-to-nia/convert-to-nia.c @@ -39,6 +39,16 @@ https://skia-review.googlesource.com/c/skia/+/290618 // compiling it. #define WUFFS_IMPLEMENTATION +// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when +// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs' +// functions have static storage. +// +// This can help the compiler ignore or discard unused code, which can produce +// faster compiles and smaller binaries. Other motivations are discussed in the +// "ALLOW STATIC IMPLEMENTATION" section of +// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt +#define WUFFS_CONFIG__STATIC_FUNCTIONS + // Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of // release/c/etc.c choose which parts of Wuffs to build. That file contains the // entire Wuffs standard library, implementing a variety of codecs and file diff --git a/example/crc32/crc32.cc b/example/crc32/crc32.cc index edc140b9..e1dc82ce 100644 --- a/example/crc32/crc32.cc +++ b/example/crc32/crc32.cc @@ -42,9 +42,13 @@ for a C++ compiler $CXX, such as clang++ or g++. // compiling it. #define WUFFS_IMPLEMENTATION -// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but it -// demonstrates making all of Wuffs' functions have static storage. The -// motivation is discussed in the "ALLOW STATIC IMPLEMENTATION" section of +// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when +// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs' +// functions have static storage. +// +// This can help the compiler ignore or discard unused code, which can produce +// faster compiles and smaller binaries. Other motivations are discussed in the +// "ALLOW STATIC IMPLEMENTATION" section of // https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt #define WUFFS_CONFIG__STATIC_FUNCTIONS diff --git a/example/gifplayer/gifplayer.c b/example/gifplayer/gifplayer.c index f692792c..79676f0a 100644 --- a/example/gifplayer/gifplayer.c +++ b/example/gifplayer/gifplayer.c @@ -71,6 +71,16 @@ micros_since_start(struct timespec* now) { // compiling it. #define WUFFS_IMPLEMENTATION +// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when +// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs' +// functions have static storage. +// +// This can help the compiler ignore or discard unused code, which can produce +// faster compiles and smaller binaries. Other motivations are discussed in the +// "ALLOW STATIC IMPLEMENTATION" section of +// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt +#define WUFFS_CONFIG__STATIC_FUNCTIONS + // Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of // release/c/etc.c choose which parts of Wuffs to build. That file contains the // entire Wuffs standard library, implementing a variety of codecs and file diff --git a/example/imageviewer/imageviewer.cc b/example/imageviewer/imageviewer.cc index eba687bb..4214ba2e 100644 --- a/example/imageviewer/imageviewer.cc +++ b/example/imageviewer/imageviewer.cc @@ -50,6 +50,16 @@ The Escape key quits. // compiling it. #define WUFFS_IMPLEMENTATION +// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when +// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs' +// functions have static storage. +// +// This can help the compiler ignore or discard unused code, which can produce +// faster compiles and smaller binaries. Other motivations are discussed in the +// "ALLOW STATIC IMPLEMENTATION" section of +// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt +#define WUFFS_CONFIG__STATIC_FUNCTIONS + // Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of // release/c/etc.c choose which parts of Wuffs to build. That file contains the // entire Wuffs standard library, implementing a variety of codecs and file diff --git a/example/json-to-cbor/json-to-cbor.cc b/example/json-to-cbor/json-to-cbor.cc index 3e1b12d3..4129de5d 100644 --- a/example/json-to-cbor/json-to-cbor.cc +++ b/example/json-to-cbor/json-to-cbor.cc @@ -46,6 +46,16 @@ for a C++ compiler $CXX, such as clang++ or g++. // compiling it. #define WUFFS_IMPLEMENTATION +// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when +// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs' +// functions have static storage. +// +// This can help the compiler ignore or discard unused code, which can produce +// faster compiles and smaller binaries. Other motivations are discussed in the +// "ALLOW STATIC IMPLEMENTATION" section of +// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt +#define WUFFS_CONFIG__STATIC_FUNCTIONS + // Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of // release/c/etc.c choose which parts of Wuffs to build. That file contains the // entire Wuffs standard library, implementing a variety of codecs and file diff --git a/example/jsonfindptrs/jsonfindptrs.cc b/example/jsonfindptrs/jsonfindptrs.cc index 56e02cfc..f1ad4682 100644 --- a/example/jsonfindptrs/jsonfindptrs.cc +++ b/example/jsonfindptrs/jsonfindptrs.cc @@ -78,6 +78,16 @@ for a C++ compiler $CXX, such as clang++ or g++. // compiling it. #define WUFFS_IMPLEMENTATION +// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when +// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs' +// functions have static storage. +// +// This can help the compiler ignore or discard unused code, which can produce +// faster compiles and smaller binaries. Other motivations are discussed in the +// "ALLOW STATIC IMPLEMENTATION" section of +// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt +#define WUFFS_CONFIG__STATIC_FUNCTIONS + // Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of // release/c/etc.c choose which parts of Wuffs to build. That file contains the // entire Wuffs standard library, implementing a variety of codecs and file diff --git a/example/jsonptr/jsonptr.cc b/example/jsonptr/jsonptr.cc index 3d72c58e..184177ff 100644 --- a/example/jsonptr/jsonptr.cc +++ b/example/jsonptr/jsonptr.cc @@ -114,6 +114,16 @@ for a C++ compiler $CXX, such as clang++ or g++. // compiling it. #define WUFFS_IMPLEMENTATION +// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when +// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs' +// functions have static storage. +// +// This can help the compiler ignore or discard unused code, which can produce +// faster compiles and smaller binaries. Other motivations are discussed in the +// "ALLOW STATIC IMPLEMENTATION" section of +// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt +#define WUFFS_CONFIG__STATIC_FUNCTIONS + // Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of // release/c/etc.c choose which parts of Wuffs to build. That file contains the // entire Wuffs standard library, implementing a variety of codecs and file diff --git a/example/sdl-imageviewer/sdl-imageviewer.cc b/example/sdl-imageviewer/sdl-imageviewer.cc index fbe251e4..f9e1c418 100644 --- a/example/sdl-imageviewer/sdl-imageviewer.cc +++ b/example/sdl-imageviewer/sdl-imageviewer.cc @@ -51,6 +51,16 @@ isn't otherwise doing anything. // compiling it. #define WUFFS_IMPLEMENTATION +// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when +// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs' +// functions have static storage. +// +// This can help the compiler ignore or discard unused code, which can produce +// faster compiles and smaller binaries. Other motivations are discussed in the +// "ALLOW STATIC IMPLEMENTATION" section of +// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt +#define WUFFS_CONFIG__STATIC_FUNCTIONS + // Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of // release/c/etc.c choose which parts of Wuffs to build. That file contains the // entire Wuffs standard library, implementing a variety of codecs and file diff --git a/example/zcat/zcat.c b/example/zcat/zcat.c index 746b08fc..4b4abee8 100644 --- a/example/zcat/zcat.c +++ b/example/zcat/zcat.c @@ -35,6 +35,16 @@ for a C compiler $CC, such as clang or gcc. // compiling it. #define WUFFS_IMPLEMENTATION +// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when +// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs' +// functions have static storage. +// +// This can help the compiler ignore or discard unused code, which can produce +// faster compiles and smaller binaries. Other motivations are discussed in the +// "ALLOW STATIC IMPLEMENTATION" section of +// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt +#define WUFFS_CONFIG__STATIC_FUNCTIONS + // Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of // release/c/etc.c choose which parts of Wuffs to build. That file contains the // entire Wuffs standard library, implementing a variety of codecs and file diff --git a/internal/cgen/base/fundamental-public.h b/internal/cgen/base/fundamental-public.h index 90a5243d..3bba0249 100644 --- a/internal/cgen/base/fundamental-public.h +++ b/internal/cgen/base/fundamental-public.h @@ -122,9 +122,12 @@ // -------- -// Define WUFFS_CONFIG__STATIC_FUNCTIONS to make all of Wuffs' functions have -// static storage. The motivation is discussed in the "ALLOW STATIC -// IMPLEMENTATION" section of +// Define WUFFS_CONFIG__STATIC_FUNCTIONS (combined with WUFFS_IMPLEMENTATION) +// to make all of Wuffs' functions have static storage. +// +// This can help the compiler ignore or discard unused code, which can produce +// faster compiles and smaller binaries. Other motivations are discussed in the +// "ALLOW STATIC IMPLEMENTATION" section of // https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt #if defined(WUFFS_CONFIG__STATIC_FUNCTIONS) #define WUFFS_BASE__MAYBE_STATIC static diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 709ea263..c50f8b72 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -177,9 +177,12 @@ extern "C" { // -------- -// Define WUFFS_CONFIG__STATIC_FUNCTIONS to make all of Wuffs' functions have -// static storage. The motivation is discussed in the "ALLOW STATIC -// IMPLEMENTATION" section of +// Define WUFFS_CONFIG__STATIC_FUNCTIONS (combined with WUFFS_IMPLEMENTATION) +// to make all of Wuffs' functions have static storage. +// +// This can help the compiler ignore or discard unused code, which can produce +// faster compiles and smaller binaries. Other motivations are discussed in the +// "ALLOW STATIC IMPLEMENTATION" section of // https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt #if defined(WUFFS_CONFIG__STATIC_FUNCTIONS) #define WUFFS_BASE__MAYBE_STATIC static