Skip to content

Commit d11f8f4

Browse files
committed
minimize const_cast usage
1 parent 4df6e3e commit d11f8f4

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

llvm/include/llvm/CGData/StableFunctionMap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ struct StableFunctionMap {
163163
HashToFuncs[FuncEntry->Hash].Entries.emplace_back(std::move(FuncEntry));
164164
}
165165

166-
void deserializeLazyLoadingEntry(HashFuncsMapType::iterator It);
166+
void deserializeLazyLoadingEntry(HashFuncsMapType::iterator It) const;
167167

168168
/// Eagerly deserialize all the unloaded entries in the lazy loading map.
169-
void deserializeLazyLoadingEntries();
169+
void deserializeLazyLoadingEntries() const;
170170

171171
bool isLazilyLoaded() const { return (bool)Buffer; }
172172

llvm/lib/CGData/StableFunctionMap.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ size_t StableFunctionMap::size(SizeType Type) const {
117117
case UniqueHashCount:
118118
return HashToFuncs.size();
119119
case TotalFunctionCount: {
120-
const_cast<StableFunctionMap *>(this)->deserializeLazyLoadingEntries();
120+
deserializeLazyLoadingEntries();
121121
size_t Count = 0;
122122
for (auto &Funcs : HashToFuncs)
123123
Count += Funcs.second.Entries.size();
124124
return Count;
125125
}
126126
case MergeableFunctionCount: {
127-
const_cast<StableFunctionMap *>(this)->deserializeLazyLoadingEntries();
127+
deserializeLazyLoadingEntries();
128128
size_t Count = 0;
129129
for (auto &[Hash, Funcs] : HashToFuncs)
130130
if (Funcs.Entries.size() >= 2)
@@ -144,18 +144,18 @@ StableFunctionMap::at(HashFuncsMapType::key_type FunctionHash) const {
144144
}
145145

146146
void StableFunctionMap::deserializeLazyLoadingEntry(
147-
HashFuncsMapType::iterator It) {
147+
HashFuncsMapType::iterator It) const {
148148
assert(isLazilyLoaded() && "Cannot deserialize non-lazily-loaded map");
149149
auto& [Hash, Storage] = *It;
150150
std::call_once(Storage.LazyLoadFlag, [this, HashArg = Hash, &StorageArg = Storage]() {
151151
for (auto Offset : StorageArg.Offsets)
152152
StableFunctionMapRecord::deserializeEntry(
153-
reinterpret_cast<const unsigned char *>(Offset), HashArg, this,
153+
reinterpret_cast<const unsigned char *>(Offset), HashArg, const_cast<StableFunctionMap *>(this),
154154
ReadStableFunctionMapNames);
155155
});
156156
}
157157

158-
void ::StableFunctionMap::deserializeLazyLoadingEntries() {
158+
void StableFunctionMap::deserializeLazyLoadingEntries() const {
159159
if (!isLazilyLoaded())
160160
return;
161161
for (auto It = HashToFuncs.begin(); It != HashToFuncs.end(); ++It)
@@ -166,7 +166,7 @@ const StableFunctionMap::HashFuncsMapType &
166166
StableFunctionMap::getFunctionMap() const {
167167
// Ensure all entries are deserialized before returning the raw map.
168168
if (isLazilyLoaded())
169-
const_cast<StableFunctionMap *>(this)->deserializeLazyLoadingEntries();
169+
deserializeLazyLoadingEntries();
170170
return HashToFuncs;
171171
}
172172

0 commit comments

Comments
 (0)