Skip to content

Commit 0facca3

Browse files
committed
Avoid unnecessary function call
1 parent f9a2595 commit 0facca3

File tree

2 files changed

+157
-1
lines changed

2 files changed

+157
-1
lines changed

lib/node_modules/@stdlib/array/filled/lib/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ function filledarray( value ) {
213213
} else {
214214
arr = new ctor( arguments[1], arguments[2], arguments[3] );
215215
}
216-
gfill( arr.length, value, arr, 1 );
216+
if ( arr.length > 0 && value !== 0 ) { // i.e., nonzero
217+
gfill( arr.length, value, arr, 1 );
218+
}
217219
return arr;
218220
}
219221

lib/node_modules/@stdlib/array/filled/test/test.js

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,20 @@ tape( 'the function returns a filled array (default, length)', function test( t
704704
t.end();
705705
});
706706

707+
tape( 'the function returns a filled array (value=0, default, length)', function test( t ) {
708+
var expected;
709+
var arr;
710+
711+
expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );
712+
713+
arr = filledarray( 0.0, 5 );
714+
t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' );
715+
t.strictEqual( arr.length, expected.length, 'returns expected value' );
716+
t.deepEqual( arr, expected, 'returns expected value' );
717+
718+
t.end();
719+
});
720+
707721
tape( 'the function returns a filled array (dtype=float64, length)', function test( t ) {
708722
var expected;
709723
var arr;
@@ -718,6 +732,20 @@ tape( 'the function returns a filled array (dtype=float64, length)', function te
718732
t.end();
719733
});
720734

735+
tape( 'the function returns a filled array (value=0, dtype=float64, length)', function test( t ) {
736+
var expected;
737+
var arr;
738+
739+
expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );
740+
741+
arr = filledarray( 0.0, 5, 'float64' );
742+
t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' );
743+
t.strictEqual( arr.length, expected.length, 'returns expected value' );
744+
t.deepEqual( arr, expected, 'returns expected value' );
745+
746+
t.end();
747+
});
748+
721749
tape( 'the function returns a filled array (dtype=float32, length)', function test( t ) {
722750
var expected;
723751
var arr;
@@ -732,6 +760,20 @@ tape( 'the function returns a filled array (dtype=float32, length)', function te
732760
t.end();
733761
});
734762

763+
tape( 'the function returns a filled array (value=0, dtype=float32, length)', function test( t ) {
764+
var expected;
765+
var arr;
766+
767+
expected = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );
768+
769+
arr = filledarray( 0.0, 5, 'float32' );
770+
t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' );
771+
t.strictEqual( arr.length, expected.length, 'returns expected value' );
772+
t.deepEqual( arr, expected, 'returns expected value' );
773+
774+
t.end();
775+
});
776+
735777
tape( 'the function returns a filled array (dtype=int32, length)', function test( t ) {
736778
var expected;
737779
var arr;
@@ -746,6 +788,20 @@ tape( 'the function returns a filled array (dtype=int32, length)', function test
746788
t.end();
747789
});
748790

791+
tape( 'the function returns a filled array (value=0, dtype=int32, length)', function test( t ) {
792+
var expected;
793+
var arr;
794+
795+
expected = new Int32Array( [ 0, 0, 0, 0, 0 ] );
796+
797+
arr = filledarray( 0, 5, 'int32' );
798+
t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' );
799+
t.strictEqual( arr.length, expected.length, 'returns expected value' );
800+
t.deepEqual( arr, expected, 'returns expected value' );
801+
802+
t.end();
803+
});
804+
749805
tape( 'the function returns a filled array (dtype=uint32, length)', function test( t ) {
750806
var expected;
751807
var arr;
@@ -760,6 +816,20 @@ tape( 'the function returns a filled array (dtype=uint32, length)', function tes
760816
t.end();
761817
});
762818

819+
tape( 'the function returns a filled array (value=0, dtype=uint32, length)', function test( t ) {
820+
var expected;
821+
var arr;
822+
823+
expected = new Uint32Array( [ 0, 0, 0, 0, 0 ] );
824+
825+
arr = filledarray( 0, 5, 'uint32' );
826+
t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' );
827+
t.strictEqual( arr.length, expected.length, 'returns expected value' );
828+
t.deepEqual( arr, expected, 'returns expected value' );
829+
830+
t.end();
831+
});
832+
763833
tape( 'the function returns a filled array (dtype=int16, length)', function test( t ) {
764834
var expected;
765835
var arr;
@@ -774,6 +844,20 @@ tape( 'the function returns a filled array (dtype=int16, length)', function test
774844
t.end();
775845
});
776846

847+
tape( 'the function returns a filled array (value=0, dtype=int16, length)', function test( t ) {
848+
var expected;
849+
var arr;
850+
851+
expected = new Int16Array( [ 0, 0, 0, 0, 0 ] );
852+
853+
arr = filledarray( 0, 5, 'int16' );
854+
t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' );
855+
t.strictEqual( arr.length, expected.length, 'returns expected value' );
856+
t.deepEqual( arr, expected, 'returns expected value' );
857+
858+
t.end();
859+
});
860+
777861
tape( 'the function returns a filled array (dtype=uint16, length)', function test( t ) {
778862
var expected;
779863
var arr;
@@ -788,6 +872,20 @@ tape( 'the function returns a filled array (dtype=uint16, length)', function tes
788872
t.end();
789873
});
790874

875+
tape( 'the function returns a filled array (value=0, dtype=uint16, length)', function test( t ) {
876+
var expected;
877+
var arr;
878+
879+
expected = new Uint16Array( [ 0, 0, 0, 0, 0 ] );
880+
881+
arr = filledarray( 0, 5, 'uint16' );
882+
t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' );
883+
t.strictEqual( arr.length, expected.length, 'returns expected value' );
884+
t.deepEqual( arr, expected, 'returns expected value' );
885+
886+
t.end();
887+
});
888+
791889
tape( 'the function returns a filled array (dtype=int8, length)', function test( t ) {
792890
var expected;
793891
var arr;
@@ -802,6 +900,20 @@ tape( 'the function returns a filled array (dtype=int8, length)', function test(
802900
t.end();
803901
});
804902

903+
tape( 'the function returns a filled array (value=0, dtype=int8, length)', function test( t ) {
904+
var expected;
905+
var arr;
906+
907+
expected = new Int8Array( [ 0, 0, 0, 0, 0 ] );
908+
909+
arr = filledarray( 0, 5, 'int8' );
910+
t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' );
911+
t.strictEqual( arr.length, expected.length, 'returns expected value' );
912+
t.deepEqual( arr, expected, 'returns expected value' );
913+
914+
t.end();
915+
});
916+
805917
tape( 'the function returns a filled array (dtype=uint8, length)', function test( t ) {
806918
var expected;
807919
var arr;
@@ -816,6 +928,20 @@ tape( 'the function returns a filled array (dtype=uint8, length)', function test
816928
t.end();
817929
});
818930

931+
tape( 'the function returns a filled array (value=0, dtype=uint8, length)', function test( t ) {
932+
var expected;
933+
var arr;
934+
935+
expected = new Uint8Array( [ 0, 0, 0, 0, 0 ] );
936+
937+
arr = filledarray( 0, 5, 'uint8' );
938+
t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' );
939+
t.strictEqual( arr.length, expected.length, 'returns expected value' );
940+
t.deepEqual( arr, expected, 'returns expected value' );
941+
942+
t.end();
943+
});
944+
819945
tape( 'the function returns a filled array (dtype=uint8c, length)', function test( t ) {
820946
var expected;
821947
var arr;
@@ -830,6 +956,20 @@ tape( 'the function returns a filled array (dtype=uint8c, length)', function tes
830956
t.end();
831957
});
832958

959+
tape( 'the function returns a filled array (value=0, dtype=uint8c, length)', function test( t ) {
960+
var expected;
961+
var arr;
962+
963+
expected = new Uint8ClampedArray( [ 0, 0, 0, 0, 0 ] );
964+
965+
arr = filledarray( 0, 5, 'uint8c' );
966+
t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' );
967+
t.strictEqual( arr.length, expected.length, 'returns expected value' );
968+
t.deepEqual( arr, expected, 'returns expected value' );
969+
970+
t.end();
971+
});
972+
833973
tape( 'the function returns a filled array (dtype=generic, length)', function test( t ) {
834974
var expected;
835975
var arr;
@@ -844,6 +984,20 @@ tape( 'the function returns a filled array (dtype=generic, length)', function te
844984
t.end();
845985
});
846986

987+
tape( 'the function returns a filled array (value=0, dtype=generic, length)', function test( t ) {
988+
var expected;
989+
var arr;
990+
991+
expected = [ 0, 0, 0, 0, 0 ];
992+
993+
arr = filledarray( 0, 5, 'generic' );
994+
t.strictEqual( instanceOf( arr, Array ), true, 'returns expected value' );
995+
t.strictEqual( arr.length, expected.length, 'returns expected value' );
996+
t.deepEqual( arr, expected, 'returns expected value' );
997+
998+
t.end();
999+
});
1000+
8471001
tape( 'the function returns a filled array (default, array)', function test( t ) {
8481002
var expected;
8491003
var arr;

0 commit comments

Comments
 (0)