Skip to content

[ClangImporter] Save a bit of malloc traffic with BumpPtrAllocator #27552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions include/swift/Basic/StringExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "swift/Basic/LLVM.h"
#include "swift/Basic/OptionSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/Allocator.h"
Expand Down Expand Up @@ -65,6 +64,8 @@ namespace swift {

public:
StringRef copyString(StringRef string);

llvm::BumpPtrAllocator &getAllocator() { return Allocator; }
};

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

public:
/// Construct a new inherited name set with the given parent.
explicit InheritedNameSet(const InheritedNameSet *parent) : Parent(parent) { }
InheritedNameSet(const InheritedNameSet *parent,
llvm::BumpPtrAllocator &allocator)
: Parent(parent), Names(allocator) { }

// Add a new name to the set.
void add(StringRef name);
Expand Down
8 changes: 4 additions & 4 deletions lib/ClangImporter/ImportName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1842,10 +1842,10 @@ const InheritedNameSet *NameImporter::getAllPropertyNames(
}

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

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