Flutter Engine
The Flutter Engine
third_party
dart-lang
sdk
runtime
vm
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
5
#include "
vm/zone_text_buffer.h
"
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
14
namespace
dart
{
15
16
ZoneTextBuffer::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
24
void
ZoneTextBuffer::Clear
() {
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
32
bool
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
assert.h
dart::BaseTextBuffer::capacity_
intptr_t capacity_
Definition:
text_buffer.h:51
dart::BaseTextBuffer::buffer_
char * buffer_
Definition:
text_buffer.h:50
dart::BaseTextBuffer::length_
intptr_t length_
Definition:
text_buffer.h:52
dart::Utils::Maximum
static constexpr T Maximum(T x, T y)
Definition:
utils.h:41
dart::ZoneTextBuffer::ZoneTextBuffer
ZoneTextBuffer(Zone *zone, intptr_t initial_capacity=64)
Definition:
zone_text_buffer.cc:16
dart::ZoneTextBuffer::Clear
void Clear()
Definition:
zone_text_buffer.cc:24
dart::Zone
Definition:
unit_test_custom_zone.h:19
dart::Zone::Realloc
ElementType * Realloc(ElementType *old_array, intptr_t old_length, intptr_t new_length)
Definition:
unit_test_custom_zone.h:30
dart::Zone::Alloc
ElementType * Alloc(intptr_t length)
Definition:
unit_test_custom_zone.h:25
ASSERT
#define ASSERT(E)
Definition:
entrypoints_verification_test.cc:25
dart
Definition:
dart_vm.cc:33
gn.find_headers.len
len
Definition:
find_headers.py:30
object.h
os.h
globals.h
utils.h
zone.h
zone_text_buffer.h
Generated on Sun Jun 23 2024 21:55:51 for Flutter Engine by
1.9.4