[llvm] 472e1a0 - [Support] Use std::clamp (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 27 21:21:37 PDT 2022


Author: Kazu Hirata
Date: 2022-08-27T21:21:08-07:00
New Revision: 472e1a065d6f673290bdf393b412be5e4fa565c0

URL: https://github.com/llvm/llvm-project/commit/472e1a065d6f673290bdf393b412be5e4fa565c0
DIFF: https://github.com/llvm/llvm-project/commit/472e1a065d6f673290bdf393b412be5e4fa565c0.diff

LOG: [Support] Use std::clamp (NFC)

We can safely use std::clamp here because the call to
report_size_overflow a few lines above guarantees MinSize <= MaxSize.

Added: 
    

Modified: 
    llvm/lib/Support/SmallVector.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/SmallVector.cpp b/llvm/lib/Support/SmallVector.cpp
index 8cafbc7fad0de..062e96544734a 100644
--- a/llvm/lib/Support/SmallVector.cpp
+++ b/llvm/lib/Support/SmallVector.cpp
@@ -105,7 +105,7 @@ static size_t getNewCapacity(size_t MinSize, size_t TSize, size_t OldCapacity) {
   // In theory 2*capacity can overflow if the capacity is 64 bit, but the
   // original capacity would never be large enough for this to be a problem.
   size_t NewCapacity = 2 * OldCapacity + 1; // Always grow.
-  return std::min(std::max(NewCapacity, MinSize), MaxSize);
+  return std::clamp(NewCapacity, MinSize, MaxSize);
 }
 
 // Note: Moving this function into the header may cause performance regression.


        


More information about the llvm-commits mailing list