Skip to content

Commit f57b1c2

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 534ddc0 commit f57b1c2

File tree

1 file changed

+7
-12
lines changed
  • lib/node_modules/@stdlib/array/base/last-index-of/lib

1 file changed

+7
-12
lines changed

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
// MODULES //
2222

23-
var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
23+
var isAccessorArray = require( '@stdlib/assert/is-accessor-array' );
24+
var resolveGetter = require( '@stdlib/array/base/resolve-getter' );
2425

2526

2627
// FUNCTIONS //
@@ -81,23 +82,19 @@ function internal( x, searchElement, fromIndex ) {
8182
*
8283
* @example
8384
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
84-
* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
8585
*
86-
* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) );
86+
* var x = toAccessorArray( [ 1, 2, 3, 4 ] );
8787
*
8888
* var idx = accessors( x, 2, 3 );
8989
* // returns 1
9090
*/
9191
function accessors( x, searchElement, fromIndex ) {
92-
var data;
9392
var get;
9493
var i;
9594

96-
data = x.data;
97-
get = x.accessors[ 0 ];
98-
95+
get = resolveGetter( x );
9996
for ( i = fromIndex; i >= 0; i-- ) {
100-
if ( searchElement === get( data, i ) ) {
97+
if ( searchElement === get( x, i ) ) {
10198
return i;
10299
}
103100
}
@@ -134,7 +131,6 @@ function accessors( x, searchElement, fromIndex ) {
134131
* // returns 1
135132
*/
136133
function lastIndexOf( x, searchElement, fromIndex ) {
137-
var obj;
138134
if ( hasMethod( x, 'lastIndexOf' ) ) {
139135
return x.lastIndexOf( searchElement, fromIndex );
140136
}
@@ -146,9 +142,8 @@ function lastIndexOf( x, searchElement, fromIndex ) {
146142
} else if ( fromIndex > x.length ) {
147143
fromIndex = x.length - 1;
148144
}
149-
obj = arraylike2object( x );
150-
if ( obj.accessorProtocol ) {
151-
return accessors( obj, searchElement, fromIndex );
145+
if ( isAccessorArray( x ) ) {
146+
return accessors( x, searchElement, fromIndex );
152147
}
153148
return internal( x, searchElement, fromIndex );
154149
}

0 commit comments

Comments
 (0)