[PATCH] D100656: [Support] Don't include <algorithm> in MathExtras.h

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 16 08:44:31 PDT 2021


thakis created this revision.
thakis added a reviewer: hans.
Herald added a subscriber: dexonsmith.
thakis requested review of this revision.
Herald added a project: LLVM.

MathExtras.h is indirectly included in over 98% of LLVM's
translation units. It currently expands to over 1MB of stuff,
over which far more than half is due to <algorithm>. Since not
using <algorithm> is slighly less code, do that.

No behavior change.


https://reviews.llvm.org/D100656

Files:
  llvm/include/llvm/Support/MathExtras.h


Index: llvm/include/llvm/Support/MathExtras.h
===================================================================
--- llvm/include/llvm/Support/MathExtras.h
+++ llvm/include/llvm/Support/MathExtras.h
@@ -14,7 +14,6 @@
 #define LLVM_SUPPORT_MATHEXTRAS_H
 
 #include "llvm/Support/Compiler.h"
-#include <algorithm>
 #include <cassert>
 #include <climits>
 #include <cmath>
@@ -793,7 +792,7 @@
 /// value of the result.
 template <typename T>
 std::enable_if_t<std::is_unsigned<T>::value, T> AbsoluteDifference(T X, T Y) {
-  return std::max(X, Y) - std::min(X, Y);
+  return X > Y ? X - Y : Y - X;
 }
 
 /// Add two unsigned integers, X and Y, of type T.  Clamp the result to the


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100656.338133.patch
Type: text/x-patch
Size: 678 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210416/26055e9a/attachment.bin>


More information about the llvm-commits mailing list