Skip to content

Commit

Permalink
Clean-up range loops
Browse files Browse the repository at this point in the history
  • Loading branch information
Kernald committed Jun 1, 2021
1 parent 69de5d9 commit 6c96de0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/google/protobuf/compiler/importer.cc
Expand Up @@ -290,7 +290,7 @@ static std::string CanonicalizePath(std::string path) {
std::vector<std::string> canonical_parts;
std::vector<std::string> parts = Split(
path, "/", true); // Note: Removes empty parts.
for (auto && part : parts) {
for (const std::string& part : parts) {
if (part == ".") {
// Ignore.
} else {
Expand Down Expand Up @@ -464,7 +464,7 @@ io::ZeroCopyInputStream* DiskSourceTree::OpenVirtualFile(
return NULL;
}

for (auto && mapping : mappings_) {
for (const auto& mapping : mappings_) {
std::string temp_disk_file;
if (ApplyMapping(virtual_file, mapping.virtual_path, mapping.disk_path,
&temp_disk_file)) {
Expand Down
9 changes: 4 additions & 5 deletions src/google/protobuf/util/field_mask_util.cc
Expand Up @@ -52,7 +52,7 @@ std::string FieldMaskUtil::ToString(const FieldMask& mask) {
void FieldMaskUtil::FromString(StringPiece str, FieldMask* out) {
out->Clear();
std::vector<std::string> paths = Split(str, ",");
for (auto && path : paths) {
for (const std::string& path : paths) {
if (path.empty()) continue;
out->add_paths(path);
}
Expand Down Expand Up @@ -125,7 +125,7 @@ bool FieldMaskUtil::ToJsonString(const FieldMask& mask, std::string* out) {
bool FieldMaskUtil::FromJsonString(StringPiece str, FieldMask* out) {
out->Clear();
std::vector<std::string> paths = Split(str, ",");
for (auto && path : paths) {
for (const std::string& path : paths) {
if (path.empty()) continue;
std::string snakecase_path;
if (!CamelCaseToSnakeCase(path, &snakecase_path)) {
Expand Down Expand Up @@ -331,7 +331,7 @@ void FieldMaskTree::AddPath(const std::string& path) {
}
bool new_branch = false;
Node* node = &root_;
for (auto && part : parts) {
for (const std::string& part : parts) {
if (!new_branch && node != &root_ && node->children.empty()) {
// Path matches an existing leaf node. This means the path is already
// covered by this tree (for example, adding "foo.bar.baz" to a tree
Expand Down Expand Up @@ -416,14 +416,13 @@ void FieldMaskTree::IntersectPath(const std::string& path, FieldMaskTree* out) {
return;
}
const Node* node = &root_;
for (auto && part : parts) {
for (const std::string& node_name : parts) {
if (node->children.empty()) {
if (node != &root_) {
out->AddPath(path);
}
return;
}
const std::string& node_name = part;
const Node* result = FindPtrOrNull(node->children, node_name);
if (result == NULL) {
// No intersection found.
Expand Down

0 comments on commit 6c96de0

Please sign in to comment.