Skip to content

Commit c3138d0

Browse files
more clean up
1 parent ff22577 commit c3138d0

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

libc/utils/HdrGen/PublicAPICommand.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,11 @@ static AttributeMap collectAttributeMacros(const SpecMap &Spec,
7575
const FuncList &Funcs) {
7676
llvm::DenseMap<llvm::StringRef, llvm::Record *> MacroAttr;
7777
for (const auto &Name : Funcs) {
78-
if (!Spec.count(Name))
78+
auto Iter = Spec.find(Name);
79+
if (Iter == Spec.end())
7980
continue;
8081

81-
llvm::Record *FunctionSpec = Spec.at(Name);
82+
llvm::Record *FunctionSpec = Iter->second;
8283
std::vector<llvm::Record *> Attributes =
8384
FunctionSpec->getValueAsListOfDefs("Attributes");
8485
for (llvm::Record *Attr : Attributes)
@@ -180,7 +181,7 @@ static void writeAPIFromIndex(APIIndexer &G,
180181
llvm::raw_ostream &OS) {
181182
for (auto &Pair : G.MacroDefsMap) {
182183
const std::string &Name = Pair.first;
183-
if (G.MacroSpecMap.find(Name) == G.MacroSpecMap.end())
184+
if (!G.MacroSpecMap.count(Name))
184185
llvm::PrintFatalError(Name + " not found in any standard spec.\n");
185186

186187
llvm::Record *MacroDef = Pair.second;
@@ -190,7 +191,7 @@ static void writeAPIFromIndex(APIIndexer &G,
190191
}
191192

192193
for (auto &TypeName : G.RequiredTypes) {
193-
if (G.TypeSpecMap.find(TypeName) == G.TypeSpecMap.end())
194+
if (!G.TypeSpecMap.count(TypeName))
194195
llvm::PrintFatalError(TypeName + " not found in any standard spec.\n");
195196
OS << "#include <llvm-libc-types/" << getTypeHdrName(TypeName) << ".h>\n";
196197
}
@@ -222,16 +223,18 @@ static void writeAPIFromIndex(APIIndexer &G,
222223

223224
OS << "__BEGIN_C_DECLS\n\n";
224225
for (auto &Name : EntrypointNameList) {
225-
if (G.FunctionSpecMap.find(Name) == G.FunctionSpecMap.end()) {
226-
continue; // Functions that aren't in this header file are skipped as
227-
// opposed to erroring out because the list of functions being
228-
// iterated over is the complete list of functions with
229-
// entrypoints. Thus this is filtering out the functions that
230-
// don't go to this header file, whereas the other, similar
231-
// conditionals above are more of a sanity check.
232-
}
226+
auto Iter = G.FunctionSpecMap.find(Name);
227+
228+
// Functions that aren't in this header file are skipped as
229+
// opposed to erroring out because the list of functions being
230+
// iterated over is the complete list of functions with
231+
// entrypoints. Thus this is filtering out the functions that
232+
// don't go to this header file, whereas the other, similar
233+
// conditionals above are more of a sanity check.
234+
if (Iter == G.FunctionSpecMap.end())
235+
continue;
233236

234-
llvm::Record *FunctionSpec = G.FunctionSpecMap[Name];
237+
llvm::Record *FunctionSpec = Iter->second;
235238
llvm::Record *RetValSpec = FunctionSpec->getValueAsDef("Return");
236239
llvm::Record *ReturnType = RetValSpec->getValueAsDef("ReturnType");
237240

@@ -252,9 +255,10 @@ static void writeAPIFromIndex(APIIndexer &G,
252255

253256
// Make another pass over entrypoints to emit object declarations.
254257
for (const auto &Name : EntrypointNameList) {
255-
if (G.ObjectSpecMap.find(Name) == G.ObjectSpecMap.end())
258+
auto Iter = G.ObjectSpecMap.find(Name);
259+
if (Iter == G.ObjectSpecMap.end())
256260
continue;
257-
llvm::Record *ObjectSpec = G.ObjectSpecMap[Name];
261+
llvm::Record *ObjectSpec = Iter->second;
258262
auto Type = ObjectSpec->getValueAsString("Type");
259263
OS << "extern " << Type << " " << Name << ";\n";
260264
}
@@ -272,9 +276,8 @@ void PublicAPICommand::run(llvm::raw_ostream &OS, const ArgVector &Args,
272276
llvm::StringRef StdHeader,
273277
llvm::RecordKeeper &Records,
274278
const Command::ErrorReporter &Reporter) const {
275-
if (Args.size() != 0) {
279+
if (Args.size() != 0)
276280
Reporter.printFatalError("public_api command does not take any arguments.");
277-
}
278281

279282
APIIndexer G(StdHeader, Records);
280283
writeAPIFromIndex(G, EntrypointNameList, OS);

0 commit comments

Comments
 (0)