embedding: refactor public ArrayBufferAllocator API · nodejs/node@7671a65 (original) (raw)

`@@ -71,7 +71,7 @@ static void OnMessage(Local message, Local error) {

`

71

71

` }

`

72

72

`}

`

73

73

``

74

``

`-

void* ArrayBufferAllocator::Allocate(size_t size) {

`

``

74

`+

void* NodeArrayBufferAllocator::Allocate(size_t size) {

`

75

75

`if (zero_fill_field_ || per_process::cli_options->zero_fill_all_buffers)

`

76

76

`return UncheckedCalloc(size);

`

77

77

`else

`

`@@ -84,29 +84,29 @@ DebuggingArrayBufferAllocator::~DebuggingArrayBufferAllocator() {

`

84

84

``

85

85

`void* DebuggingArrayBufferAllocator::Allocate(size_t size) {

`

86

86

` Mutex::ScopedLock lock(mutex_);

`

87

``

`-

void* data = ArrayBufferAllocator::Allocate(size);

`

``

87

`+

void* data = NodeArrayBufferAllocator::Allocate(size);

`

88

88

`RegisterPointerInternal(data, size);

`

89

89

`return data;

`

90

90

`}

`

91

91

``

92

92

`void* DebuggingArrayBufferAllocator::AllocateUninitialized(size_t size) {

`

93

93

` Mutex::ScopedLock lock(mutex_);

`

94

``

`-

void* data = ArrayBufferAllocator::AllocateUninitialized(size);

`

``

94

`+

void* data = NodeArrayBufferAllocator::AllocateUninitialized(size);

`

95

95

`RegisterPointerInternal(data, size);

`

96

96

`return data;

`

97

97

`}

`

98

98

``

99

99

`void DebuggingArrayBufferAllocator::Free(void* data, size_t size) {

`

100

100

` Mutex::ScopedLock lock(mutex_);

`

101

101

`UnregisterPointerInternal(data, size);

`

102

``

`-

ArrayBufferAllocator::Free(data, size);

`

``

102

`+

NodeArrayBufferAllocator::Free(data, size);

`

103

103

`}

`

104

104

``

105

105

`void* DebuggingArrayBufferAllocator::Reallocate(void* data,

`

106

106

`size_t old_size,

`

107

107

`size_t size) {

`

108

108

` Mutex::ScopedLock lock(mutex_);

`

109

``

`-

void* ret = ArrayBufferAllocator::Reallocate(data, old_size, size);

`

``

109

`+

void* ret = NodeArrayBufferAllocator::Reallocate(data, old_size, size);

`

110

110

`if (ret == nullptr) {

`

111

111

`if (size == 0) // i.e. equivalent to free().

`

112

112

`UnregisterPointerInternal(data, old_size);

`

`@@ -149,11 +149,15 @@ void DebuggingArrayBufferAllocator::RegisterPointerInternal(void* data,

`

149

149

` allocations_[data] = size;

`

150

150

`}

`

151

151

``

152

``

`-

ArrayBufferAllocator* CreateArrayBufferAllocator() {

`

153

``

`-

if (per_process::cli_options->debug_arraybuffer_allocations)

`

154

``

`-

return new DebuggingArrayBufferAllocator();

`

``

152

`+

std::unique_ptr ArrayBufferAllocator::Create(bool debug) {

`

``

153

`+

if (debug || per_process::cli_options->debug_arraybuffer_allocations)

`

``

154

`+

return std::make_unique();

`

155

155

`else

`

156

``

`-

return new ArrayBufferAllocator();

`

``

156

`+

return std::make_unique();

`

``

157

`+

}

`

``

158

+

``

159

`+

ArrayBufferAllocator* CreateArrayBufferAllocator() {

`

``

160

`+

return ArrayBufferAllocator::Create().release();

`

157

161

`}

`

158

162

``

159

163

`void FreeArrayBufferAllocator(ArrayBufferAllocator* allocator) {

`