Skip to content

Commit 91c33f0

Browse files
committed
refactor: reduce overhead by using specialized utilities
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent c7f060f commit 91c33f0

File tree

1 file changed

+9
-14
lines changed
  • lib/node_modules/@stdlib/array/base/index-of-same-value/lib

1 file changed

+9
-14
lines changed

lib/node_modules/@stdlib/array/base/index-of-same-value/lib/main.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020

2121
// MODULES //
2222

23+
var isAccessorArray = require( '@stdlib/assert/is-accessor-array' );
2324
var isComplexLike = require( '@stdlib/assert/is-complex-like' );
2425
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2526
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex' );
2627
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );
2728
var isComplexTypedArray = require( '@stdlib/array/base/assert/is-complex-typed-array' );
2829
var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' );
29-
var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
30+
var resolveGetter = require( '@stdlib/array/base/resolve-getter' );
3031
var isSameValue = require( '@stdlib/assert/is-same-value' );
3132
var real = require( '@stdlib/complex/float64/real' );
3233
var imag = require( '@stdlib/complex/float64/imag' );
@@ -63,30 +64,26 @@ function indexed( x, searchElement, fromIndex ) {
6364
* Returns the index of the first element which equals a provided search element according to the same value algorithm.
6465
*
6566
* @private
66-
* @param {Object} x - input array object
67+
* @param {Collection} x - input array object
6768
* @param {*} searchElement - search element
6869
* @param {NonNegativeInteger} fromIndex - starting index (inclusive)
6970
* @returns {integer} index
7071
*
7172
* @example
7273
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
73-
* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
7474
*
75-
* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );
75+
* var x = toAccessorArray( [ 1, 2, 3, 4 ] );
7676
*
7777
* var idx = accessors( x, 2, 0 );
7878
* // returns 1
7979
*/
8080
function accessors( x, searchElement, fromIndex ) {
81-
var data;
8281
var get;
8382
var i;
8483

85-
data = x.data;
86-
get = x.accessors[ 0 ];
87-
88-
for ( i = fromIndex; i < data.length; i++ ) {
89-
if ( isSameValue( searchElement, get( data, i ) ) ) {
84+
get = resolveGetter( x );
85+
for ( i = fromIndex; i < x.length; i++ ) {
86+
if ( isSameValue( searchElement, get( x, i ) ) ) {
9087
return i;
9188
}
9289
}
@@ -198,22 +195,20 @@ function boolean( x, searchElement, fromIndex ) {
198195
* // returns 1
199196
*/
200197
function indexOfSameValue( x, searchElement, fromIndex ) {
201-
var obj;
202198
if ( fromIndex < 0 ) {
203199
fromIndex += x.length;
204200
if ( fromIndex < 0 ) {
205201
fromIndex = 0;
206202
}
207203
}
208-
obj = arraylike2object( x );
209-
if ( obj.accessorProtocol ) {
204+
if ( isAccessorArray( x ) ) {
210205
if ( isComplexTypedArray( x ) ) {
211206
return complex( x, searchElement, fromIndex );
212207
}
213208
if ( isBooleanArray( x ) ) {
214209
return boolean( x, searchElement, fromIndex );
215210
}
216-
return accessors( obj, searchElement, fromIndex );
211+
return accessors( x, searchElement, fromIndex );
217212
}
218213
return indexed( x, searchElement, fromIndex );
219214
}

0 commit comments

Comments
 (0)