Files
swift-mirror/include/swift/Syntax/SyntaxArena.h
Rintaro Ishizaki 057254dbc1 [Syntax] Bump allocate and cache/reuse RawSyntax
Introduced SyntaxArena for managing memory and cache.

SyntaxArena holds BumpPtrAllocator as a allocation storage.
RawSyntax is now able to be constructed with normal heap allocation, or
by SyntaxArena. RawSyntax has ManualMemory flag which indicates it's managed by
SyntaxArena. If the flag is true, its Retain()/Release() is no-op thus it's
never destructed by IntrusiveRefCntPtr.
This speedups the memory allocation for RawSyntax.

Also, in Syntax parsing, "token" RawSyntax is reused if:
a) It's not string literal with >16 length; and
b) It doesn't contain random text trivia (e.g. comment).
This reduces the overall allocation cost.
2018-02-02 01:27:06 +09:00

46 lines
1.3 KiB
C++

//===--- SyntaxArena.h - Syntax Tree Memory Allocation ----------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines SyntaxArena that is Memory manager for Syntax nodes.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_SYNTAX_SYNTAXARENA_H
#define SWIFT_SYNTAX_SYNTAXARENA_H
#include "llvm/Support/Allocator.h"
namespace swift {
namespace syntax {
/// Memory manager for Syntax nodes.
class SyntaxArena {
SyntaxArena(const SyntaxArena &) = delete;
void operator=(const SyntaxArena &) = delete;
public:
struct Implementation;
Implementation &Impl;
SyntaxArena();
~SyntaxArena();
llvm::BumpPtrAllocator &getAllocator() const;
void *Allocate(size_t size, size_t alignment);
void *AllocateRawSyntax(size_t size, size_t alignment);
};
} // namespace syntax
} // namespace swift
#endif