cppcheck icon indicating copy to clipboard operation
cppcheck copied to clipboard

reduced size of `ValueFlow::Value`

Open firewave opened this issue 1 year ago • 2 comments

firewave avatar Sep 08 '24 18:09 firewave

Still need to clean up the macros. And I would like to get the TODOs addressed as well.

The constant for the padding also needs to be adjusted so takes the default alignment into account and we do not overpad. I was also thinking about a macro.

firewave avatar Sep 08 '24 18:09 firewave

This is mostly clean now and reduces the size from 168 bytes to 136 bytes.

But the debugpath code is broken. And I still want to cleanup the redundancies in the config.h macros.

firewave avatar Sep 20 '24 18:09 firewave

This is mostly clean now and reduces the size from 168 bytes to 136 bytes.

But the debugpath code is broken. And I still want to cleanup the redundancies in the config.h macros.

I backed out the debugpath changes for now. The size is now only reduced from 168 bytes to 152 bytes.

firewave avatar Dec 14 '24 13:12 firewave

I backed out the debugpath changes for now. The size is now only reduced from 168 bytes to 152 bytes.

Does it make sense to hide debugpath behind some build flag? If somebody needs it then he can build cppcheck with that. Or maybe leave it out in the release builds?

danmar avatar Dec 15 '24 10:12 danmar

Does it make sense to hide debugpath behind some build flag? If somebody needs it then he can build cppcheck with that. Or maybe leave it out in the release builds?

That is included in the --debug output so changing that will potentially open a can of worms.

firewave avatar Dec 15 '24 16:12 firewave

In the future, I would like to introduce dynamic attributes as some of these attributes are only used for some rare occasions, and it doesnt make sense to always have a static field for such attributes:

struct Attributes {

    template<class A>
    const auto& get() const
    {
        return read<A>().get();
    }

    template<class A, class T>
    void set(T x) const
    {
        return read<A>().set(x);
    }

    template<class A>
    const A& read() const
    {
        return static_cast<const A*>(attr.at(key<A>()).get());
    }

    template<class A>
    A& write()
    {
        return static_cast<A*>(attr.at(key<A>()).get());
    }

private:
    std::unordered_map<std::type_index, ValuePtr<Attribute>> attrs;

    template<class A>
    static std::type_index key()
    {
        return std::type_index(typeid(A));
    }
};

We could probably make this copy-on-write as well to make the copies cheaper.

pfultz2 avatar Dec 15 '24 22:12 pfultz2

In the future, I would like to introduce dynamic attributes as some of these attributes are only used for some rare occasions, and it doesnt make sense to always have a static field for such attributes:

That would be something to consider. If I find the time (haha) I will give it a look.

firewave avatar Dec 16 '24 19:12 firewave