[clang-tidy] performance-inefficient-vector-operation: Support proto repeated field
authorHaojian Wu <hokein@google.com>
Mon, 16 Sep 2019 08:54:10 +0000 (08:54 +0000)
committerHaojian Wu <hokein@google.com>
Mon, 16 Sep 2019 08:54:10 +0000 (08:54 +0000)
commitad7a7cea89717daf6b56f35e4bc0b95afe0498a2
tree0a1c2b56486350046143365ccb0f5672639793d7
parentb026b3e53d67c258f8b750e3fc44fa1609185dee
[clang-tidy] performance-inefficient-vector-operation: Support proto repeated field

Summary:
Finds calls that add element to protobuf repeated field in a loop
without calling Reserve() before the loop. Calling Reserve() first can avoid
unnecessary memory reallocations.

A new option EnableProto is added to guard this feature.

Patch by Cong Liu!

Reviewers: gribozavr, alexfh, hokein, aaron.ballman

Reviewed By: hokein

Subscribers: lebedev.ri, xazax.hun, Eugene.Zelenko, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D67135

llvm-svn: 371963
clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp
clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h
clang-tools-extra/docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
clang-tools-extra/test/clang-tidy/performance-inefficient-vector-operation.cpp