Skip to content

Commit 9c09dd2

Browse files
authored
refactor: avoid repeatedly accessing the same element
Signed-off-by: Athan <[email protected]>
1 parent 07dba24 commit 9c09dd2

File tree

1 file changed

+7
-4
lines changed
  • lib/node_modules/@stdlib/blas/ext/base/gnansumors/lib

1 file changed

+7
-4
lines changed

lib/node_modules/@stdlib/blas/ext/base/gnansumors/lib/accessors.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ function gnansumors( N, x, strideX, offsetX ) {
5151
var xget;
5252
var sum;
5353
var ix;
54+
var v;
5455
var i;
5556

5657
// Cache reference to array data:
@@ -61,15 +62,17 @@ function gnansumors( N, x, strideX, offsetX ) {
6162

6263
ix = offsetX;
6364
if ( strideX === 0 ) {
64-
if ( isnan( xget( xbuf, ix ) ) ) {
65+
v = xget( xbuf, ix );
66+
if ( isnan( v ) ) {
6567
return 0.0;
6668
}
67-
return N * xget( xbuf, ix );
69+
return N * v;
6870
}
6971
sum = 0.0;
7072
for ( i = 0; i < N; i++ ) {
71-
if ( isnan( xget( xbuf, ix ) ) === false ) {
72-
sum += xget( xbuf, ix );
73+
v = xget( xbuf, ix );
74+
if ( isnan( v ) === false ) {
75+
sum += v;
7376
}
7477
ix += strideX;
7578
}

0 commit comments

Comments
 (0)