Welcome! Log In Create A New Profile

Advanced

[njs] A small Array.prototype.sort() optimization.

March 29, 2017 08:58AM
details: http://hg.nginx.org/njs/rev/90743d1bb614
branches:
changeset: 323:90743d1bb614
user: Igor Sysoev <igor@sysoev.ru>
date: Wed Mar 29 15:54:37 2017 +0300
description:
A small Array.prototype.sort() optimization.

diffstat:

njs/njs_array.c | 34 ++++++++++++++++++----------------
1 files changed, 18 insertions(+), 16 deletions(-)

diffs (52 lines):

diff -r 8cdbd57379e8 -r 90743d1bb614 njs/njs_array.c
--- a/njs/njs_array.c Wed Mar 29 15:54:33 2017 +0300
+++ b/njs/njs_array.c Wed Mar 29 15:54:37 2017 +0300
@@ -1802,9 +1802,9 @@ njs_array_prototype_sort_continuation(nj
if (njs_is_number(&sort->retval)) {

/*
- * The sort function is impelemented with the insertion sort algorithm.
+ * The sort function is implemented with the insertion sort algorithm.
* Its worst and average computational complexity is O^2. This point
- * should be considired as return point from comparison function so
+ * should be considered as return point from comparison function so
* "goto next" moves control to the appropriate step of the algorithm.
* The first iteration also goes there because sort->retval is zero.
*/
@@ -1824,20 +1824,22 @@ njs_array_prototype_sort_continuation(nj
do {
if (n > 0) {

- if (njs_is_valid(&start[n]) && njs_is_valid(&start[n - 1])) {
- arguments[0] = njs_value_void;
-
- /* GC: array elt, array */
- arguments[1] = start[n - 1];
- arguments[2] = start[n];
-
- sort->index = n;
-
- return njs_function_apply(vm, sort->function, arguments, 3,
- (njs_index_t) &sort->retval);
- }
-
- if (!njs_is_valid(&start[n - 1]) && njs_is_valid(&start[n])) {
+ if (njs_is_valid(&start[n])) {
+
+ if (njs_is_valid(&start[n - 1])) {
+ arguments[0] = njs_value_void;
+
+ /* GC: array elt, array */
+ arguments[1] = start[n - 1];
+ arguments[2] = start[n];
+
+ sort->index = n;
+
+ return njs_function_apply(vm, sort->function,
+ arguments, 3,
+ (njs_index_t) &sort->retval);
+ }
+
/* Move invalid values to the end of array. */
goto swap;
}
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] A small Array.prototype.sort() optimization.

Igor Sysoev 700 March 29, 2017 08:58AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 322
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready