Flutter Engine
The Flutter Engine
zone_text_buffer.cc
Go to the documentation of this file.
1// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
6
7#include "platform/assert.h"
8#include "platform/globals.h"
9#include "platform/utils.h"
10#include "vm/object.h"
11#include "vm/os.h"
12#include "vm/zone.h"
13
14namespace dart {
15
16ZoneTextBuffer::ZoneTextBuffer(Zone* zone, intptr_t initial_capacity)
17 : zone_(zone) {
18 ASSERT(initial_capacity > 0);
19 buffer_ = reinterpret_cast<char*>(zone->Alloc<char>(initial_capacity));
20 capacity_ = initial_capacity;
21 buffer_[length_] = '\0';
22}
23
25 const intptr_t initial_capacity = 64;
26 buffer_ = reinterpret_cast<char*>(zone_->Alloc<char>(initial_capacity));
27 capacity_ = initial_capacity;
28 length_ = 0;
29 buffer_[length_] = '\0';
30}
31
32bool ZoneTextBuffer::EnsureCapacity(intptr_t len) {
33 intptr_t remaining = capacity_ - length_;
34 if (remaining <= len) {
35 intptr_t new_capacity = capacity_ + Utils::Maximum(capacity_, len);
36 buffer_ = zone_->Realloc<char>(buffer_, capacity_, new_capacity);
37 capacity_ = new_capacity;
38 }
39 return true;
40}
41
42} // namespace dart
static constexpr T Maximum(T x, T y)
Definition: utils.h:41
ZoneTextBuffer(Zone *zone, intptr_t initial_capacity=64)
ElementType * Realloc(ElementType *old_array, intptr_t old_length, intptr_t new_length)
ElementType * Alloc(intptr_t length)
#define ASSERT(E)
Definition: dart_vm.cc:33