@@ -1560,8 +1560,14 @@ function sortperm(A::AbstractArray;
15601560                  order:: Ordering = Forward,
15611561                  scratch:: Union{Vector{<:Integer}, Nothing} = nothing ,
15621562                  dims... ) # to optionally specify dims argument
1563-     ordr =  ord (lt,by,rev,order)
1564-     if  ordr ===  Forward &&  isa (A,Vector) &&  eltype (A)<: Integer 
1563+     if  rev ===  true 
1564+         _sortperm (A; alg, order= ord (lt, by, true , order), scratch, dims... )
1565+     else 
1566+         _sortperm (A; alg, order= ord (lt, by, nothing , order), scratch, dims... )
1567+     end 
1568+ end 
1569+ function  _sortperm (A:: AbstractArray ; alg, order, scratch, dims... )
1570+     if  order ===  Forward &&  isa (A,Vector) &&  eltype (A)<: Integer 
15651571        n =  length (A)
15661572        if  n >  1 
15671573            min, max =  extrema (A)
@@ -1573,7 +1579,7 @@ function sortperm(A::AbstractArray;
15731579        end 
15741580    end 
15751581    ix =  copymutable (LinearIndices (A))
1576-     sort! (ix; alg, order =  Perm (ordr , vec (A)), scratch, dims... )
1582+     sort! (ix; alg, order =  Perm (order , vec (A)), scratch, dims... )
15771583end 
15781584
15791585
@@ -1615,7 +1621,7 @@ julia> sortperm!(p, A; dims=2); p
16151621 2  4 
16161622``` 
16171623""" 
1618- function  sortperm! (ix:: AbstractArray{T} , A:: AbstractArray ;
1624+ @inline   function  sortperm! (ix:: AbstractArray{T} , A:: AbstractArray ;
16191625                   alg:: Algorithm = DEFAULT_UNSTABLE,
16201626                   lt= isless,
16211627                   by= identity,
@@ -1630,7 +1636,12 @@ function sortperm!(ix::AbstractArray{T}, A::AbstractArray;
16301636    if  ! initialized
16311637        ix .=  LinearIndices (A)
16321638    end 
1633-     sort! (ix; alg, order =  Perm (ord (lt, by, rev, order), vec (A)), scratch, dims... )
1639+ 
1640+     if  rev ===  true 
1641+         sort! (ix; alg, order= Perm (ord (lt, by, true , order), vec (A)), scratch, dims... )
1642+     else 
1643+         sort! (ix; alg, order= Perm (ord (lt, by, nothing , order), vec (A)), scratch, dims... )
1644+     end 
16341645end 
16351646
16361647#  sortperm for vectors of few unique integers
0 commit comments