Skip to content

[clang-tidy] Check request: performance-redundant-std-vector #146607

@denzor200

Description

@denzor200

Need a check that will find cases where std::vector is used redundantly for fixed-size, statically initialized data. The check will suggest a replacement with std::array for better performance and clarity.

BEFORE:

bool foo(int val) {
  std::vector<int> v = { 1,2, 5, 10, 33 };
  return std::range::find(v, val) != v.end();
}

AFTER:

bool foo(int val) {
  std::array<int, 5> v = { 1,2, 5, 10, 33 };
  return std::range::find(v, val) != v.end();
}

In C++17 mode the check will produce replacement with CTAD usage:

bool foo(int val) {
  std::array v = { 1,2, 5, 10, 33 };
  return std::range::find(v, val) != v.end();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions