Skip to content

Commit 7a6a795

Browse files
authored
[NFC][equivalenceClass] Refactor coding style in EquivalenceClasses.h. (#135467)
1 parent d49063b commit 7a6a795

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

llvm/include/llvm/ADT/EquivalenceClasses.h

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,15 @@ template <class ElemTy> class EquivalenceClasses {
7979
// ECValue ctor - Start out with EndOfList pointing to this node, Next is
8080
// Null, isLeader = true.
8181
ECValue(const ElemTy &Elt)
82-
: Leader(this), Next((ECValue*)(intptr_t)1), Data(Elt) {}
82+
: Leader(this),
83+
Next(reinterpret_cast<ECValue *>(static_cast<intptr_t>(1))),
84+
Data(Elt) {}
8385

8486
const ECValue *getLeader() const {
85-
if (isLeader()) return this;
86-
if (Leader->isLeader()) return Leader;
87+
if (isLeader())
88+
return this;
89+
if (Leader->isLeader())
90+
return Leader;
8791
// Path compression.
8892
return Leader = Leader->getLeader();
8993
}
@@ -95,12 +99,16 @@ template <class ElemTy> class EquivalenceClasses {
9599

96100
void setNext(const ECValue *NewNext) const {
97101
assert(getNext() == nullptr && "Already has a next pointer!");
98-
Next = (const ECValue*)((intptr_t)NewNext | (intptr_t)isLeader());
102+
Next = reinterpret_cast<const ECValue *>(
103+
reinterpret_cast<intptr_t>(NewNext) |
104+
static_cast<intptr_t>(isLeader()));
99105
}
100106

101107
public:
102-
ECValue(const ECValue &RHS) : Leader(this), Next((ECValue*)(intptr_t)1),
103-
Data(RHS.Data) {
108+
ECValue(const ECValue &RHS)
109+
: Leader(this),
110+
Next(reinterpret_cast<ECValue *>(static_cast<intptr_t>(1))),
111+
Data(RHS.Data) {
104112
// Only support copying of singleton nodes.
105113
assert(RHS.isLeader() && RHS.getNext() == nullptr && "Not a singleton!");
106114
}
@@ -109,7 +117,8 @@ template <class ElemTy> class EquivalenceClasses {
109117
const ElemTy &getData() const { return Data; }
110118

111119
const ECValue *getNext() const {
112-
return (ECValue*)((intptr_t)Next & ~(intptr_t)1);
120+
return reinterpret_cast<ECValue *>(reinterpret_cast<intptr_t>(Next) &
121+
~static_cast<intptr_t>(1));
113122
}
114123
};
115124

@@ -124,9 +133,7 @@ template <class ElemTy> class EquivalenceClasses {
124133

125134
public:
126135
EquivalenceClasses() = default;
127-
EquivalenceClasses(const EquivalenceClasses &RHS) {
128-
operator=(RHS);
129-
}
136+
EquivalenceClasses(const EquivalenceClasses &RHS) { operator=(RHS); }
130137

131138
EquivalenceClasses &operator=(const EquivalenceClasses &RHS) {
132139
TheMapping.clear();
@@ -160,9 +167,7 @@ template <class ElemTy> class EquivalenceClasses {
160167
return member_iterator(ECV.isLeader() ? &ECV : nullptr);
161168
}
162169

163-
member_iterator member_end() const {
164-
return member_iterator(nullptr);
165-
}
170+
member_iterator member_end() const { return member_iterator(nullptr); }
166171

167172
iterator_range<member_iterator> members(const ECValue &ECV) const {
168173
return make_range(member_begin(ECV), member_end());
@@ -294,7 +299,8 @@ template <class ElemTy> class EquivalenceClasses {
294299
}
295300
member_iterator unionSets(member_iterator L1, member_iterator L2) {
296301
assert(L1 != member_end() && L2 != member_end() && "Illegal inputs!");
297-
if (L1 == L2) return L1; // Unifying the same two sets, noop.
302+
if (L1 == L2)
303+
return L1; // Unifying the same two sets, noop.
298304

299305
// Otherwise, this is a real union operation. Set the end of the L1 list to
300306
// point to the L2 leader node.
@@ -350,7 +356,7 @@ template <class ElemTy> class EquivalenceClasses {
350356
return *this;
351357
}
352358

353-
member_iterator operator++(int) { // postincrement operators.
359+
member_iterator operator++(int) { // postincrement operators.
354360
member_iterator tmp = *this;
355361
++*this;
356362
return tmp;

0 commit comments

Comments
 (0)