5 #include "src/regexp/regexp-stack.h" 7 #include "src/isolate.h" 12 RegExpStackScope::RegExpStackScope(Isolate* isolate)
13 : regexp_stack_(isolate->regexp_stack()) {
15 regexp_stack_->EnsureCapacity(0);
19 RegExpStackScope::~RegExpStackScope() {
21 regexp_stack_->Reset();
24 RegExpStack::RegExpStack() : isolate_(nullptr) {}
26 RegExpStack::~RegExpStack() {
31 char* RegExpStack::ArchiveStack(
char* to) {
32 size_t size =
sizeof(thread_local_);
33 MemCopy(reinterpret_cast<void*>(to), &thread_local_, size);
34 thread_local_ = ThreadLocal();
39 char* RegExpStack::RestoreStack(
char* from) {
40 size_t size =
sizeof(thread_local_);
41 MemCopy(&thread_local_, reinterpret_cast<void*>(from), size);
46 void RegExpStack::Reset() {
47 if (thread_local_.memory_size_ > kMinimumStackSize) {
48 DeleteArray(thread_local_.memory_);
49 thread_local_ = ThreadLocal();
54 void RegExpStack::ThreadLocal::Free() {
55 if (memory_size_ > 0) {
62 Address RegExpStack::EnsureCapacity(
size_t size) {
63 if (size > kMaximumStackSize)
return kNullAddress;
64 if (size < kMinimumStackSize) size = kMinimumStackSize;
65 if (thread_local_.memory_size_ < size) {
66 byte* new_memory = NewArray<byte>(size);
67 if (thread_local_.memory_size_ > 0) {
69 MemCopy(new_memory + size - thread_local_.memory_size_,
70 thread_local_.memory_, thread_local_.memory_size_);
71 DeleteArray(thread_local_.memory_);
73 thread_local_.memory_ = new_memory;
74 thread_local_.memory_size_ = size;
75 thread_local_.limit_ =
76 reinterpret_cast<Address
>(new_memory) + kStackLimitSlack * kPointerSize;
78 return reinterpret_cast<Address
>(thread_local_.memory_) +
79 thread_local_.memory_size_;