Skip to content

Commit

Permalink
Re-enable precompilation for common Parsers routines (#148)
Browse files Browse the repository at this point in the history
* Re-enable precompilation for common Parsers routines

* enable precompile

* add compat for SnoopPrecompile

* fix compat
  • Loading branch information
quinnj committed Nov 4, 2022
1 parent a740baf commit 38615bb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ version = "2.5.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c"

[compat]
SnoopPrecompile = "1"
julia = "1.6"

[extras]
Expand Down
35 changes: 29 additions & 6 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
function _precompile_()
ccall(:jl_generating_output, Cint, ()) == 1 || return nothing
precompile(Tuple{typeof(Parsers.parse), Type{Int64}, String})
precompile(Tuple{typeof(Parsers.parse), Type{Float64}, String})
precompile(Tuple{typeof(Parsers.parse), Type{Date}, String})
using SnoopPrecompile

@precompile_setup begin
# Putting some things in `setup` can reduce the size of the
# precompile file and potentially make loading faster.
options = Parsers.Options()
pos = 1
val = "123"
len = length(val)
@precompile_all_calls begin
# all calls in this block will be precompiled, regardless of whether
# they belong to your package or not (on Julia 1.8 and higher)
for T in (String, Int32, Int64, Float64, BigFloat, Dates.Date, Dates.DateTime, Dates.Time, Bool)
for buf in (codeunits(val), Vector(codeunits(val)))
Parsers.xparse(T, buf, pos, len, options)
Parsers.xparse(T, buf, pos, len, options, Any)
end
end

for T in (Int32, Int64, Float64, BigFloat, Dates.Date, Dates.DateTime, Dates.Time, Bool)
for buf in (val, SubString(val, 1:3), Vector(codeunits(val)), view(Vector(codeunits(val)), 1:3))
try
Parsers.parse(T, buf, options)
catch
end
Parsers.tryparse(T, buf, options)
end
end
end
end
_precompile_()

2 comments on commit 38615bb

@quinnj
Copy link
Member Author

@quinnj quinnj commented on 38615bb Nov 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/71615

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.5.0 -m "<description of version>" 38615bb0719c4acbec33a5b2d88caeb434bce124
git push origin v2.5.0

Please sign in to comment.