Skip to content

Commit

Permalink
Optimize conversion of UInt to GapObj
Browse files Browse the repository at this point in the history
Before:

    julia> @Btime GAP.julia_to_gap(UInt64(2^60));
      54.260 ns (4 allocations: 88 bytes)

After:

    julia> @Btime GAP.julia_to_gap(UInt64(2^60));
      19.893 ns (2 allocations: 48 bytes)
  • Loading branch information
fingolfin authored and ThomasBreuer committed Apr 18, 2024
1 parent f639cb7 commit eae6963
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/julia_to_gap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ julia_to_gap(x::UInt32) = Int64(x)
julia_to_gap(x::UInt16) = Int64(x)
julia_to_gap(x::UInt8) = Int64(x)

function julia_to_gap(x::UInt)
x < (1<<60) && return Int64(x)
return ccall((:ObjInt_UInt, libgap), GapObj, (UInt64, ), x)
end

## BigInts are converted via a ccall
function julia_to_gap(x::BigInt)
x in -1<<60:(1<<60-1) && return Int64(x)
Expand Down

0 comments on commit eae6963

Please sign in to comment.