@@ -683,16 +683,7 @@ void UDPWrap::OnAlloc(uv_handle_t* handle,
683
683
}
684
684
685
685
uv_buf_t UDPWrap::OnAlloc (size_t suggested_size) {
686
- Environment* env = this ->env ();
687
- uv_buf_t buf;
688
- {
689
- NoArrayBufferZeroFillScope no_zero_fill_scope (env->isolate_data ());
690
- std::unique_ptr<BackingStore> bs =
691
- ArrayBuffer::NewBackingStore (env->isolate (), suggested_size);
692
- buf = uv_buf_init (static_cast <char *>(bs->Data ()), bs->ByteLength ());
693
- env->released_allocated_buffers ()->emplace (buf.base , std::move (bs));
694
- }
695
- return buf;
686
+ return this ->env ()->allocate_managed_buffer (suggested_size);
696
687
}
697
688
698
689
void UDPWrap::OnRecv (uv_udp_t * handle,
@@ -710,22 +701,13 @@ void UDPWrap::OnRecv(ssize_t nread,
710
701
unsigned int flags) {
711
702
Environment* env = this ->env ();
712
703
Isolate* isolate = env->isolate ();
713
-
714
- std::unique_ptr<BackingStore> bs;
715
- if (buf_.base != nullptr ) {
716
- auto map = env->released_allocated_buffers ();
717
- auto it = map->find (buf_.base );
718
- CHECK_NE (it, map->end ());
719
- bs = std::move (it->second );
720
- map->erase (it);
721
- }
722
-
704
+ std::unique_ptr<BackingStore> bs = env->release_managed_buffer (buf_);
723
705
if (nread == 0 && addr == nullptr ) {
724
706
return ;
725
707
}
726
708
727
- HandleScope handle_scope (isolate);
728
- Context::Scope context_scope (env->context ());
709
+ const HandleScope handle_scope (isolate);
710
+ const Context::Scope context_scope (env->context ());
729
711
730
712
Local<Value> argv[] = {
731
713
Integer::New (isolate, static_cast <int32_t >(nread)),
@@ -739,7 +721,7 @@ void UDPWrap::OnRecv(ssize_t nread,
739
721
} else if (nread == 0 ) {
740
722
bs = ArrayBuffer::NewBackingStore (isolate, 0 );
741
723
} else {
742
- NoArrayBufferZeroFillScope no_zero_fill_scope (env->isolate_data ());
724
+ const NoArrayBufferZeroFillScope no_zero_fill_scope (env->isolate_data ());
743
725
bs = BackingStore::Reallocate (isolate, std::move (bs), nread);
744
726
}
745
727
0 commit comments