@@ -1037,68 +1037,60 @@ void ConnectionsList::New(const FunctionCallbackInfo<Value>& args) {
1037
1037
1038
1038
void ConnectionsList::All (const FunctionCallbackInfo<Value>& args) {
1039
1039
Isolate* isolate = args.GetIsolate ();
1040
- Local<Context> context = isolate->GetCurrentContext ();
1041
1040
1042
- Local<Array> all = Array::New (isolate);
1043
1041
ConnectionsList* list;
1044
1042
1045
1043
ASSIGN_OR_RETURN_UNWRAP (&list, args.Holder ());
1046
1044
1047
- uint32_t i = 0 ;
1045
+ std::vector<Local<Value>> result;
1046
+ result.reserve (list->all_connections_ .size ());
1048
1047
for (auto parser : list->all_connections_ ) {
1049
- if (all->Set (context, i++, parser->object ()).IsNothing ()) {
1050
- return ;
1051
- }
1048
+ result.emplace_back (parser->object ());
1052
1049
}
1053
1050
1054
- return args.GetReturnValue ().Set (all);
1051
+ return args.GetReturnValue ().Set (
1052
+ Array::New (isolate, result.data (), result.size ()));
1055
1053
}
1056
1054
1057
1055
void ConnectionsList::Idle (const FunctionCallbackInfo<Value>& args) {
1058
1056
Isolate* isolate = args.GetIsolate ();
1059
- Local<Context> context = isolate->GetCurrentContext ();
1060
1057
1061
- Local<Array> idle = Array::New (isolate);
1062
1058
ConnectionsList* list;
1063
1059
1064
1060
ASSIGN_OR_RETURN_UNWRAP (&list, args.Holder ());
1065
1061
1066
- uint32_t i = 0 ;
1062
+ std::vector<Local<Value>> result;
1063
+ result.reserve (list->all_connections_ .size ());
1067
1064
for (auto parser : list->all_connections_ ) {
1068
1065
if (parser->last_message_start_ == 0 ) {
1069
- if (idle->Set (context, i++, parser->object ()).IsNothing ()) {
1070
- return ;
1071
- }
1066
+ result.emplace_back (parser->object ());
1072
1067
}
1073
1068
}
1074
1069
1075
- return args.GetReturnValue ().Set (idle);
1070
+ return args.GetReturnValue ().Set (
1071
+ Array::New (isolate, result.data (), result.size ()));
1076
1072
}
1077
1073
1078
1074
void ConnectionsList::Active (const FunctionCallbackInfo<Value>& args) {
1079
1075
Isolate* isolate = args.GetIsolate ();
1080
- Local<Context> context = isolate->GetCurrentContext ();
1081
1076
1082
- Local<Array> active = Array::New (isolate);
1083
1077
ConnectionsList* list;
1084
1078
1085
1079
ASSIGN_OR_RETURN_UNWRAP (&list, args.Holder ());
1086
1080
1087
- uint32_t i = 0 ;
1081
+ std::vector<Local<Value>> result;
1082
+ result.reserve (list->active_connections_ .size ());
1088
1083
for (auto parser : list->active_connections_ ) {
1089
- if (active->Set (context, i++, parser->object ()).IsNothing ()) {
1090
- return ;
1091
- }
1084
+ result.emplace_back (parser->object ());
1092
1085
}
1093
1086
1094
- return args.GetReturnValue ().Set (active);
1087
+ return args.GetReturnValue ().Set (
1088
+ Array::New (isolate, result.data (), result.size ()));
1095
1089
}
1096
1090
1097
1091
void ConnectionsList::Expired (const FunctionCallbackInfo<Value>& args) {
1098
1092
Isolate* isolate = args.GetIsolate ();
1099
- Local<Context> context = isolate->GetCurrentContext ();
1100
1093
1101
- Local<Array> expired = Array::New (isolate);
1102
1094
ConnectionsList* list;
1103
1095
1104
1096
ASSIGN_OR_RETURN_UNWRAP (&list, args.Holder ());
@@ -1110,7 +1102,7 @@ void ConnectionsList::Expired(const FunctionCallbackInfo<Value>& args) {
1110
1102
static_cast <uint64_t >(args[1 ].As <Uint32>()->Value ()) * 1000000 ;
1111
1103
1112
1104
if (headers_timeout == 0 && request_timeout == 0 ) {
1113
- return args.GetReturnValue ().Set (expired );
1105
+ return args.GetReturnValue ().Set (Array::New (isolate, 0 ) );
1114
1106
} else if (request_timeout > 0 && headers_timeout > request_timeout) {
1115
1107
std::swap (headers_timeout, request_timeout);
1116
1108
}
@@ -1121,9 +1113,11 @@ void ConnectionsList::Expired(const FunctionCallbackInfo<Value>& args) {
1121
1113
const uint64_t request_deadline =
1122
1114
request_timeout > 0 ? now - request_timeout : 0 ;
1123
1115
1124
- uint32_t i = 0 ;
1125
1116
auto iter = list->active_connections_ .begin ();
1126
1117
auto end = list->active_connections_ .end ();
1118
+
1119
+ std::vector<Local<Value>> result;
1120
+ result.reserve (list->active_connections_ .size ());
1127
1121
while (iter != end) {
1128
1122
Parser* parser = *iter;
1129
1123
iter++;
@@ -1136,15 +1130,14 @@ void ConnectionsList::Expired(const FunctionCallbackInfo<Value>& args) {
1136
1130
request_deadline > 0 &&
1137
1131
parser->last_message_start_ < request_deadline)
1138
1132
) {
1139
- if (expired->Set (context, i++, parser->object ()).IsNothing ()) {
1140
- return ;
1141
- }
1133
+ result.emplace_back (parser->object ());
1142
1134
1143
1135
list->active_connections_ .erase (parser);
1144
1136
}
1145
1137
}
1146
1138
1147
- return args.GetReturnValue ().Set (expired);
1139
+ return args.GetReturnValue ().Set (
1140
+ Array::New (isolate, result.data (), result.size ()));
1148
1141
}
1149
1142
1150
1143
const llhttp_settings_t Parser::settings = {
0 commit comments