src: use a std::vector for preload_modules#12241
src: use a std::vector for preload_modules#12241sam-github wants to merge 1 commit intonodejs:masterfrom
Conversation
A dynamically allocated array was being used, simplify the memory management by using std::vector.
kkoopa
left a comment
There was a problem hiding this comment.
Left some minor comments which likely have no actual performance impact.
| if (!preload_modules.empty()) { | ||
| 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.
A do-while loop would avoid one unnecessary bounds check. There is at least one element in the vector.
| } | ||
| args_consumed += 1; | ||
| local_preload_modules[preload_module_count++] = module; | ||
| preload_modules.push_back(module); |
There was a problem hiding this comment.
It should be possible to reserve space in the vector before inserting elements.
There was a problem hiding this comment.
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