-- v2: mshtml: Define skip_prefix without using a magic number.
From: Alex Henrie alexhenrie24@gmail.com
--- dlls/mshtml/omnavigator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/mshtml/omnavigator.c b/dlls/mshtml/omnavigator.c index 646017aee9e..cfabd22cf29 100644 --- a/dlls/mshtml/omnavigator.c +++ b/dlls/mshtml/omnavigator.c @@ -1261,7 +1261,7 @@ static HRESULT WINAPI OmNavigator_get_appVersion(IOmNavigator *iface, BSTR *p) WCHAR *user_agent; unsigned len; HRESULT hres; - const unsigned skip_prefix = 8; /* strlen("Mozilla/") */ + const unsigned skip_prefix = strlen("Mozilla/");
TRACE("(%p)->(%p)\n", This, p);
On Thu Aug 17 15:54:00 2023 +0000, Gabriel Ivăncescu wrote:
In terms of optimization, as long as the address isn't taken, a const local variable will literally get replaced by the direct constant, as if using a #define macro or an enum, how is static better? The compiler actually has to do *more* work to optimize out a static constant like this, since it has to actually remove the variable (because it's not addressed from anything via its address and not visible outside the compilation unit, so it can be removed, but still that's an extra effort it has to do). const local variables aren't even allocated as variables when optimizing. Even if they did, it's because they're caching some expensive calculation, which is actually good. static const makes sense when you want to have one pre-allocated instance of the variable, when you need to actually read it via its address. This is not the case here.
All good points, thanks for the explanation. I've pushed a new patch that uses strlen. The function call is optimized out on GCC and Clang, so the final machine code is identical. Still waiting to hear Jacek's opinion.
This merge request was approved by Jacek Caban.