|
111 | 111 | * ereport_domain() directly, or preferably they can override the TEXTDOMAIN
|
112 | 112 | * macro.
|
113 | 113 | *
|
| 114 | + * When __builtin_constant_p is available and elevel >= ERROR we make a call |
| 115 | + * to errstart_cold() instead of errstart(). This version of the function is |
| 116 | + * marked with pg_attribute_cold which will coax supporting compilers into |
| 117 | + * generating code which is more optimized towards non-ERROR cases. Because |
| 118 | + * we use __builtin_constant_p() in the condition, when elevel is not a |
| 119 | + * compile-time constant, or if it is, but it's < ERROR, the compiler has no |
| 120 | + * need to generate any code for this branch. It can simply call errstart() |
| 121 | + * unconditionally. |
| 122 | + * |
114 | 123 | * If elevel >= ERROR, the call will not return; we try to inform the compiler
|
115 | 124 | * of that via pg_unreachable(). However, no useful optimization effect is
|
116 | 125 | * obtained unless the compiler sees elevel as a compile-time constant, else
|
|
124 | 133 | #define ereport_domain(elevel, domain, ...) \
|
125 | 134 | do { \
|
126 | 135 | pg_prevent_errno_in_scope(); \
|
127 |
| - if (errstart(elevel, domain)) \ |
| 136 | + if (__builtin_constant_p(elevel) && (elevel) >= ERROR ? \ |
| 137 | + errstart_cold(elevel, domain) : \ |
| 138 | + errstart(elevel, domain)) \ |
128 | 139 | __VA_ARGS__, errfinish(__FILE__, __LINE__, PG_FUNCNAME_MACRO); \
|
129 | 140 | if (__builtin_constant_p(elevel) && (elevel) >= ERROR) \
|
130 | 141 | pg_unreachable(); \
|
|
146 | 157 |
|
147 | 158 | #define TEXTDOMAIN NULL
|
148 | 159 |
|
| 160 | +extern bool pg_attribute_cold errstart_cold(int elevel, const char *domain); |
149 | 161 | extern bool errstart(int elevel, const char *domain);
|
150 | 162 | extern void errfinish(const char *filename, int lineno, const char *funcname);
|
151 | 163 |
|
|
0 commit comments