-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: use a std::vector for preload_modules #12241
src: use a std::vector for preload_modules #12241
Conversation
A dynamically allocated array was being used, simplify the memory management by using std::vector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some minor comments which likely have no actual performance impact.
Local<Array> array = Array::New(env->isolate()); | ||
for (unsigned int i = 0; i < preload_module_count; ++i) { | ||
for (unsigned int i = 0; i < preload_modules.size(); ++i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A do-while loop would avoid one unnecessary bounds check. There is at least one element in the vector.
@@ -3717,7 +3711,7 @@ static void ParseArgs(int* argc, | |||
exit(9); | |||
} | |||
args_consumed += 1; | |||
local_preload_modules[preload_module_count++] = module; | |||
preload_modules.push_back(module); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be possible to reserve space in the vector before inserting elements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How? This is only inserting one element, I don't know how many -r
options were passed.
@kkoopa I appreciate the feedback, but I think readability and minimization of the diff outweights the cost of one additional integer comparison, which is anyhow dwarfed by the cost of actually requiring the module(s). |
reserve argc, optionally do a shrink_to_fit at the end
…On April 6, 2017 9:57:09 PM GMT+03:00, Sam Roberts ***@***.***> wrote:
sam-github commented on this pull request.
> @@ -3717,7 +3711,7 @@ static void ParseArgs(int* argc,
exit(9);
}
args_consumed += 1;
- local_preload_modules[preload_module_count++] = module;
+ preload_modules.push_back(module);
How? This is only inserting one element, I don't know how many `-r`
options were passed.
--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#12241 (comment)
|
Readability is unaffected and essentially subjective, so that is not the best reason. Keeping the diff size down is however a valid reason.
…On April 6, 2017 9:59:01 PM GMT+03:00, Sam Roberts ***@***.***> wrote:
@kkoopa I appreciate the feedback, but I think readability and
minimization of the diff outweights the cost of one additional integer
comparison, which is anyhow dwarfed by the cost of actually requiring
the module(s).
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#12241 (comment)
|
Landed in cecdf7c |
A dynamically allocated array was being used, simplify the memory management by using std::vector. PR-URL: #12241 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
cc @sam-github |
A dynamically allocated array was being used, simplify the memory management by using std::vector. PR-URL: nodejs#12241 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Backport PR: #12677 |
A dynamically allocated array was being used, simplify the memory management by using std::vector. PR-URL: nodejs#12241 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
A dynamically allocated array was being used, simplify the memory management by using std::vector. Backport-PR-URL: #12677 PR-URL: #12241 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
A dynamically allocated array was being used, simplify the memory management by using std::vector. Backport-PR-URL: #12677 PR-URL: #12241 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
A dynamically allocated array was being used, simplify the memory
management by using std::vector.
Factored out of #12028, its unrelated and easily backportable.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
src