Change for loops to use const refs where possible.

LSC: Change for loops to use const refs, per performance-for-range-copy
clang-tidy.

This CL optimizes C++11 range-based for loops where the variable is
copied in each iteration but it would suffice to obtain it by const
reference. This is only applied to loop variables of types that are
expensive to copy which means they are not trivially copyable or have
non-trivial copy constructor or destructor.

To ensure that it is safe to replace the copy with a const reference
the following heuristic is employed:
  The loop variable is const qualified.
  The loop variable is not const, but only const methods or operators
    are invoked on it, or it is used as const reference or value
    argument in constructors or function calls.

PiperOrigin-RevId: 304179354
Change-Id: I54a9409ba8fd97ed4bbdc0a930277761c27cc04c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/68110
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/xml/cfx_xmlelement.cpp b/core/fxcrt/xml/cfx_xmlelement.cpp
index b999f5c..4745507 100644
--- a/core/fxcrt/xml/cfx_xmlelement.cpp
+++ b/core/fxcrt/xml/cfx_xmlelement.cpp
@@ -86,7 +86,7 @@
   pXMLStream->WriteString("<");
   pXMLStream->WriteString(bsNameEncoded.AsStringView());
 
-  for (auto it : attrs_) {
+  for (const auto& it : attrs_) {
     // Note, the space between attributes is added by AttributeToString which
     // writes a blank as the first character.
     pXMLStream->WriteString(
diff --git a/samples/pdfium_test_event_helper.cc b/samples/pdfium_test_event_helper.cc
index a3ddbef..a97d490 100644
--- a/samples/pdfium_test_event_helper.cc
+++ b/samples/pdfium_test_event_helper.cc
@@ -139,7 +139,7 @@
                     FPDF_PAGE page,
                     const std::string& events) {
   auto lines = StringSplit(events, '\n');
-  for (auto line : lines) {
+  for (const auto& line : lines) {
     auto command = StringSplit(line, '#');
     if (command[0].empty())
       continue;