]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/term-util: inline colors_enabled function 17702/head
authorrnhmjoj <rnhmjoj@inventati.org>
Tue, 15 Dec 2020 18:40:30 +0000 (19:40 +0100)
committerrnhmjoj <rnhmjoj@inventati.org>
Tue, 15 Dec 2020 18:40:30 +0000 (19:40 +0100)
There is no need to cache colors_enabled because the function
is now simply calling get_color_mode, which is already cached.

src/basic/terminal-util.c
src/basic/terminal-util.h

index 0092e3a2f5267d39f0bfdcf2f824de5119ac5057..7c003f80dd01b1fca3708768fe08e4ff006ac229 100644 (file)
@@ -47,7 +47,6 @@ static volatile unsigned cached_columns = 0;
 static volatile unsigned cached_lines = 0;
 
 static volatile int cached_on_tty = -1;
-static volatile int cached_colors_enabled = -1;
 static volatile int cached_color_mode = _COLOR_INVALID;
 static volatile int cached_underline_enabled = -1;
 
@@ -864,7 +863,6 @@ void reset_terminal_feature_caches(void) {
         cached_columns = 0;
         cached_lines = 0;
 
-        cached_colors_enabled = -1;
         cached_color_mode = _COLOR_INVALID;
         cached_underline_enabled = -1;
         cached_on_tty = -1;
@@ -1252,16 +1250,6 @@ ColorMode get_color_mode(void) {
         return cached_color_mode;
 }
 
-bool colors_enabled(void) {
-
-        /* Returns true if colors are considered supported on our stdout. */
-
-        if (cached_colors_enabled < 0)
-                cached_colors_enabled = get_color_mode() != COLOR_OFF;
-
-        return cached_colors_enabled;
-}
-
 bool dev_console_colors_enabled(void) {
         _cleanup_free_ char *s = NULL;
         ColorMode m;
index 11a24b26b772a188a272955a0f9782f75880a73c..75e44c8726489e1d018818aa3882cd7136f03f97 100644 (file)
@@ -148,11 +148,16 @@ void reset_terminal_feature_caches(void);
 
 bool on_tty(void);
 bool terminal_is_dumb(void);
-bool colors_enabled(void);
 ColorMode get_color_mode(void);
 bool underline_enabled(void);
 bool dev_console_colors_enabled(void);
 
+static inline bool colors_enabled(void) {
+
+        /* Returns true if colors are considered supported on our stdout. */
+        return get_color_mode() != COLOR_OFF;
+}
+
 #define DEFINE_ANSI_FUNC(name, NAME)                            \
         static inline const char *ansi_##name(void) {           \
                 return colors_enabled() ? ANSI_##NAME : "";     \