Skip to content

generator: Avoid copying quickstart list results - #16607

Open
Amanpal9 wants to merge 2 commits into
googleapis:mainfrom
Amanpal9:quickstart-const-range
Open

Amanpal9 wants to merge 2 commits into
googleapis:mainfrom
Amanpal9:quickstart-const-range

Conversation

@Amanpal9

Copy link
Copy Markdown

Summary

  • Generate quickstart range loops with auto const& to avoid copying each list result.
  • Assert the generated quickstart uses the const reference form.

Fixes #16394.

Validation

  • git diff --check passed.
  • The generator unit test was updated, but could not be run locally because CMake, Bazel, and GoogleTest dependencies are unavailable in this environment.

@Amanpal9
Amanpal9 requested a review from a team as a code owner October 30, 2026 16:01

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates a range-based loop in the scaffold generator to use a const reference (auto const&) instead of a copy, and adds a corresponding test assertion. However, as noted in the review, this change makes the subsequent std::move(r) call redundant and misleading since you cannot move from a const reference. You should update line 987 to call r.status() directly.

$library$::MakeServiceConnection()); // EDIT HERE

for (auto r : client.List/*EDIT HERE*/(location.FullName())) {
for (auto const& r : client.List/*EDIT HERE*/(location.FullName())) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Changing r to auto const& means that std::move(r) on the next line (line 987) is now redundant and misleading, as you cannot move from a const reference. It will silently fall back to a copy. Consider removing std::move and calling r.status() directly.

@colinmoy

Copy link
Copy Markdown
Collaborator

/gcbrun

@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.45%. Comparing base (778cb3a) to head (3ff34b9).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16607      +/-   ##
==========================================
+ Coverage   92.44%   92.45%   +0.01%     
==========================================
  Files        2266     2266              
  Lines      221578   221579       +1     
==========================================
+ Hits       204835   204865      +30     
+ Misses      16743    16714      -29     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@colinmoy

Copy link
Copy Markdown
Collaborator

/gharun

This branch was successfully deployed

1 active deployment
false — 4d399581 Deployed Oct 31, 2026 by Amanpal9 via Save PR ref #12743
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

generated quickstarts shoudl use const& when iterating through lists

2 participants