Menu

Potential "false positive" performance warning

2025-10-10
2025-10-10
  • Tobias Markus

    Tobias Markus - 2025-10-10

    Again, this is the perfetto source code from https://github.com/google/perfetto

    src/protozero/filtering/filter_util.cc:328:28: performance: Searching before insertion is not necessary. [stlFindInsert]
              seen_msgs.insert(nested_type);
    

    The code is as follows:

            if (seen_msgs.find(nested_type) == seen_msgs.end()) {
              seen_msgs.insert(nested_type);
              queue.emplace_back(result.nested_msg_index, nested_type);
            }
    

    While I can understand the reason for the warning, the emplace_back command does depend on it, so the find statement can't be removed in any case.

     
  • CHR

    CHR - 2025-10-10

    How about this?

    void f(std::set<int>& s, int i) {
        auto [_, b] = s.insert(i);
        if (b) {
            dostuff();
        }
    }
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.