bug-gperf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using gperf to allow switch-case over strings (in c++17)


From: Viktor Engelmann
Subject: Re: Using gperf to allow switch-case over strings (in c++17)
Date: Mon, 27 Dec 2021 13:34:33 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.1

Hello Bruno,
1) Since 'constexpr' is a built-in keyword in C++, why does --language=C++
not imply --constexpr in the first place? In other words, as a user I
would like the generated code to be optimal without any additional
command-line options.
I did it this way because I didn't want to change the behavior on
existing projects. Apart from that, I agree with your reasoning.

In the Qt Framework, things like this would be solved with a
preprocessor variable like Q_CONSTEXPR that would be
defined to constexpr or nothing at the start of the file.
If you compile with option -S, you will see that in the functions
Perfect_Hash::hash and Perfect_Hash::in_word_set the arrays are
initialized *at every invocation*.

I understand that this is because [1] specifies that
   "the function body must not contain:
    ... a definition of a variable of static ... storage duration"
correct.
But it is a performance killer! gperf is meant to generate fast code,
and one of the necessary requirements is that the arrays are prepared
once only (and preferrably in read-only storage).

I agree. I worried about this, but hadn't checked it so far.

Without adding it to gperf sources yet, I manually made the tables
static constexpr class-members (see attachment test.cpp). I'm not
sure I understand the assembler code (-S) correctly, but I think
this should solve the issue.
@Bruno: What do you say about this version?

Kind regards

Viktor

Attachment: test.cpp
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]