about summary refs log tree commit diff
path: root/absl/strings/string_view.h
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2020-02-11T18·47-0800
committerMark Barolak <mbar@google.com>2020-02-11T18·50-0500
commit98eb410c93ad059f9bba1bf43f5bb916fc92a5ea (patch)
tree4dffc4639ac9100f754b9db7ba8895322435b8ea /absl/strings/string_view.h
parentbf78e977309c4cb946914b456404141ddac1c302 (diff)
Export of internal Abseil changes
--
daa829a331a2316713681b5fe7630d1951e0fdec by Gennadiy Rozental <rogeeff@google.com>:

Eliminate Flag's destroy method.

The Abseil Flags are never destroyed. The only place where Destroy method was invoked was in some obscure place during flag registration, where we faces with duplicate retired flag registration. Regired Flag destruction is empty anyway. so we can just delete the duplicate object. The FLagImpl::Destroy is never invoked.

PiperOrigin-RevId: 294472413

--
3c159499ccde8ccdd6907b3a1ddb26be7d3f016f by Abseil Team <absl-team@google.com>:

Internal change.

PiperOrigin-RevId: 294401573

--
25910db425c50d9b9a8f8275af5a67c2935934fd by Shahriar Rouf <nafi@google.com>:

Optimize absl::string_view::compare.

Motivation: https://godbolt.org/z/Uz8DWV
PiperOrigin-RevId: 294286196
GitOrigin-RevId: daa829a331a2316713681b5fe7630d1951e0fdec
Change-Id: I818dad27ac5eb61bb7632e01224953cd882803bf
Diffstat (limited to 'absl/strings/string_view.h')
-rw-r--r--absl/strings/string_view.h18
1 files changed, 10 insertions, 8 deletions
diff --git a/absl/strings/string_view.h b/absl/strings/string_view.h
index 418dbc809680..1861ea62a9ea 100644
--- a/absl/strings/string_view.h
+++ b/absl/strings/string_view.h
@@ -398,12 +398,11 @@ class string_view {
   // on the respective sizes of the two `string_view`s to determine which is
   // smaller, equal, or greater.
   constexpr int compare(string_view x) const noexcept {
-    return CompareImpl(
-        length_, x.length_,
-        length_ == 0 || x.length_ == 0
-            ? 0
-            : ABSL_INTERNAL_STRING_VIEW_MEMCMP(
-                  ptr_, x.ptr_, length_ < x.length_ ? length_ : x.length_));
+    return CompareImpl(length_, x.length_,
+                       Min(length_, x.length_) == 0
+                           ? 0
+                           : ABSL_INTERNAL_STRING_VIEW_MEMCMP(
+                                 ptr_, x.ptr_, Min(length_, x.length_)));
   }
 
   // Overload of `string_view::compare()` for comparing a substring of the
@@ -541,12 +540,15 @@ class string_view {
 #endif
   }
 
+  static constexpr size_t Min(size_type length_a, size_type length_b) {
+    return length_a < length_b ? length_a : length_b;
+  }
+
   static constexpr int CompareImpl(size_type length_a, size_type length_b,
                                    int compare_result) {
     return compare_result == 0 ? static_cast<int>(length_a > length_b) -
                                      static_cast<int>(length_a < length_b)
-                               : static_cast<int>(compare_result > 0) -
-                                     static_cast<int>(compare_result < 0);
+                               : (compare_result < 0 ? -1 : 1);
   }
 
   const char* ptr_;