@@ -683,16 +683,7 @@ void UDPWrap::OnAlloc(uv_handle_t* handle,
683683}
684684
685685uv_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);
696687}
697688
698689void UDPWrap::OnRecv (uv_udp_t * handle,
@@ -710,22 +701,13 @@ void UDPWrap::OnRecv(ssize_t nread,
710701 unsigned int flags) {
711702 Environment* env = this ->env ();
712703 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_);
723705 if (nread == 0 && addr == nullptr ) {
724706 return ;
725707 }
726708
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 ());
729711
730712 Local<Value> argv[] = {
731713 Integer::New (isolate, static_cast <int32_t >(nread)),
@@ -739,7 +721,7 @@ void UDPWrap::OnRecv(ssize_t nread,
739721 } else if (nread == 0 ) {
740722 bs = ArrayBuffer::NewBackingStore (isolate, 0 );
741723 } else {
742- NoArrayBufferZeroFillScope no_zero_fill_scope (env->isolate_data ());
724+ const NoArrayBufferZeroFillScope no_zero_fill_scope (env->isolate_data ());
743725 bs = BackingStore::Reallocate (isolate, std::move (bs), nread);
744726 }
745727
0 commit comments