Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
datastream.cc
Go to the documentation of this file.
1// Copyright (c) 2018, 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/datastream.h"
6
8#include "vm/zone.h"
9
10namespace dart {
11
13 ASSERT(Utils::BitLength(value) <= compiler::target::kBitsPerWord);
14 WriteFixed(static_cast<compiler::target::word>(value));
15}
16
20
21void MallocWriteStream::Realloc(intptr_t new_size) {
22 const intptr_t old_offset = current_ - buffer_;
23 buffer_ = reinterpret_cast<uint8_t*>(realloc(buffer_, new_size));
24 capacity_ = buffer_ != nullptr ? new_size : 0;
25 current_ = buffer_ != nullptr ? buffer_ + old_offset : nullptr;
26}
27
28void ZoneWriteStream::Realloc(intptr_t new_size) {
29 const intptr_t old_offset = current_ - buffer_;
30 buffer_ = zone_->Realloc(buffer_, capacity_, new_size);
31 capacity_ = buffer_ != nullptr ? new_size : 0;
32 current_ = buffer_ != nullptr ? buffer_ + old_offset : nullptr;
33}
34
39
40void StreamingWriteStream::Realloc(intptr_t new_size) {
41 Flush();
42 // Check whether resetting the internal buffer by flushing gave enough space.
43 if (new_size <= capacity_) {
44 return;
45 }
46 const intptr_t new_capacity = Utils::RoundUp(new_size, 64 * KB);
47 buffer_ = reinterpret_cast<uint8_t*>(realloc(buffer_, new_capacity));
48 capacity_ = buffer_ != nullptr ? new_capacity : 0;
49 current_ = buffer_; // Flushing reset the internal buffer offset to 0.
50}
51
53 intptr_t size = current_ - buffer_;
54 callback_(callback_data_, buffer_, size);
55 flushed_size_ += size;
57}
58
59} // namespace dart
void WriteFixed(T value)
Definition datastream.h:473
void WriteTargetWord(word value)
Definition datastream.cc:12
virtual void Realloc(intptr_t new_size)
Definition datastream.cc:21
virtual void Realloc(intptr_t new_size)
Definition datastream.cc:40
static constexpr T RoundUp(T x, uintptr_t alignment, uintptr_t offset=0)
Definition utils.h:105
static constexpr size_t BitLength(int64_t value)
Definition utils.h:198
virtual void Realloc(intptr_t new_size)
Definition datastream.cc:28
ElementType * Realloc(ElementType *old_array, intptr_t old_length, intptr_t new_length)
#define ASSERT(E)
uint8_t value
constexpr intptr_t KB
Definition globals.h:528
intptr_t word
Definition globals.h:500
void * realloc(void *ptr, size_t size)
Definition allocation.cc:27