Skip to content

Commit 5831fbb

Browse files
committed
[ClangImporter] Save a bit of malloc traffic with BumpPtrAllocator
No functionality change.
1 parent b32e82c commit 5831fbb

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

include/swift/Basic/StringExtras.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "swift/Basic/LLVM.h"
2222
#include "swift/Basic/OptionSet.h"
2323
#include "llvm/ADT/SmallVector.h"
24-
#include "llvm/ADT/StringMap.h"
2524
#include "llvm/ADT/StringRef.h"
2625
#include "llvm/ADT/StringSet.h"
2726
#include "llvm/Support/Allocator.h"
@@ -65,6 +64,8 @@ namespace swift {
6564

6665
public:
6766
StringRef copyString(StringRef string);
67+
68+
llvm::BumpPtrAllocator &getAllocator() { return Allocator; }
6869
};
6970

7071
namespace camel_case {
@@ -430,11 +431,13 @@ StringRef matchLeadingTypeName(StringRef name, OmissionTypeName typeName);
430431
/// Describes a set of names with an inheritance relationship.
431432
class InheritedNameSet {
432433
const InheritedNameSet *Parent;
433-
llvm::StringSet<> Names;
434+
llvm::StringSet<llvm::BumpPtrAllocator &> Names;
434435

435436
public:
436437
/// Construct a new inherited name set with the given parent.
437-
explicit InheritedNameSet(const InheritedNameSet *parent) : Parent(parent) { }
438+
InheritedNameSet(const InheritedNameSet *parent,
439+
llvm::BumpPtrAllocator &allocator)
440+
: Parent(parent), Names(allocator) { }
438441

439442
// Add a new name to the set.
440443
void add(StringRef name);

lib/ClangImporter/ImportName.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,10 +1842,10 @@ const InheritedNameSet *NameImporter::getAllPropertyNames(
18421842
}
18431843

18441844
// Create the set of properties.
1845-
known = allProperties.insert(
1846-
{ std::pair<const clang::ObjCInterfaceDecl *, char>(classDecl,
1847-
forInstance),
1848-
llvm::make_unique<InheritedNameSet>(parentSet) }).first;
1845+
llvm::BumpPtrAllocator &alloc = scratch.getAllocator();
1846+
known = allProperties.insert({
1847+
std::pair<const clang::ObjCInterfaceDecl *, char>(classDecl, forInstance),
1848+
llvm::make_unique<InheritedNameSet>(parentSet, alloc) }).first;
18491849

18501850
// Local function to add properties from the given set.
18511851
auto addProperties = [&](clang::DeclContext::decl_range members) {

0 commit comments

Comments
 (0)