about summary refs log tree commit diff
path: root/absl/strings/string_view.h
diff options
context:
space:
mode:
Diffstat (limited to 'absl/strings/string_view.h')
-rw-r--r--absl/strings/string_view.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/absl/strings/string_view.h b/absl/strings/string_view.h
index 68b90aa3126f..841570b6713e 100644
--- a/absl/strings/string_view.h
+++ b/absl/strings/string_view.h
@@ -168,7 +168,9 @@ class string_view {
   string_view(  // NOLINT(runtime/explicit)
       const std::basic_string<char, std::char_traits<char>, Allocator>&
           str) noexcept
-      : ptr_(str.data()), length_(CheckLengthInternal(str.size())) {}
+      // This is implement in terms of `string_view(p, n)` so `str.size()`
+      // doesn't need to be reevaluated after `ptr_` is set.
+      : string_view(str.data(), str.size()) {}
 
   // Implicit constructor of a `string_view` from nul-terminated `str`. When
   // accepting possibly null strings, use `absl::NullSafeStringView(str)`