diff --git a/src/node_api_jsrt.cc b/src/node_api_jsrt.cc index e5e6241e49e..bee35a316f3 100644 --- a/src/node_api_jsrt.cc +++ b/src/node_api_jsrt.cc @@ -552,34 +552,31 @@ napi_status napi_define_class(napi_env env, } } - std::vector descriptors; - descriptors.reserve(std::max(instancePropertyCount, staticPropertyCount)); + std::vector staticDescriptors; + std::vector instanceDescriptors; + staticDescriptors.reserve(staticPropertyCount); + instanceDescriptors.reserve(instancePropertyCount); - if (instancePropertyCount > 0) { - for (size_t i = 0; i < property_count; i++) { - if ((properties[i].attributes & napi_static) == 0) { - descriptors.push_back(properties[i]); - } + for (size_t i = 0; i < property_count; i++) { + if ((properties[i].attributes & napi_static) != 0) { + staticDescriptors.push_back(properties[i]); + } else { + instanceDescriptors.push_back(properties[i]); } - - CHECK_NAPI(napi_define_properties(env, - reinterpret_cast(prototype), - descriptors.size(), - descriptors.data())); } if (staticPropertyCount > 0) { - descriptors.clear(); - for (size_t i = 0; i < property_count; i++) { - if (!(properties[i].attributes & napi_static) != 0) { - descriptors.push_back(properties[i]); - } - } - CHECK_NAPI(napi_define_properties(env, reinterpret_cast(constructor), - descriptors.size(), - descriptors.data())); + staticDescriptors.size(), + staticDescriptors.data())); + } + + if (instancePropertyCount > 0) { + CHECK_NAPI(napi_define_properties(env, + reinterpret_cast(prototype), + instanceDescriptors.size(), + instanceDescriptors.data())); } *result = reinterpret_cast(constructor);