Skip to content

Commit dd6b06c

Browse files
committed
Add @nospecialize's to reduce multiple recompilations.
1 parent 17d67b9 commit dd6b06c

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/gdal_utils.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
O = gd2gmt(dataset; band=0, bands=[], sds=0, pad=0)
2+
O = gd2gmt(dataset; band::Int=0, bands=Vector{Int}(), sds::Int=0, pad::Int=0)
33
44
Convert a GDAL raster dataset into either a GMTgrid (if type is Int16 or Float) or a GMTimage type
55
Use `band` to select a single band of the dataset. When you know that the dataset contains several
@@ -22,6 +22,9 @@ Or
2222
G = gd2gmt("NETCDF:AQUA_MODIS.20210228.L3m.DAY.NSST.sst.4km.NRT.nc:sst");
2323
"""
2424
function gd2gmt(_dataset; band::Int=0, bands=Vector{Int}(), sds::Int=0, pad::Int=0, layout::String="")::Union{GItype, GDtype}
25+
_gd2gmt(_dataset, band, bands, sds, pad, layout)
26+
end
27+
function _gd2gmt(@nospecialize(_dataset), band::Int, bands::Vector{Int}, sds::Int, pad::Int, layout::String)
2528

2629
(isa(_dataset, GMTgrid) || isa(_dataset, GMTimage) || isGMTdataset(_dataset)) && return _dataset
2730

@@ -257,7 +260,7 @@ function gd2gmt(geom::Gdal.AbstractGeometry, proj::String="")::Union{GMTdataset,
257260
end
258261

259262
# ---------------------------------------------------------------------------------------------------
260-
function gd2gmt(dataset::Gdal.AbstractDataset)
263+
function gd2gmt(@nospecialize(dataset::Gdal.AbstractDataset))
261264
# This method is for OGR formats only
262265
(Gdal.GDALGetRasterCount(dataset.ptr) >= 1) && return gd2gmt(dataset; pad=0)
263266

@@ -491,7 +494,10 @@ by `grdinfo`. An unfortunate consequence of using either GMT or GDAL to inquire
491494
`x_inc, y_inc` when reading with GDAL, and `z_min, z_max` when reading with GMT.
492495
"""
493496
function getregion(input; pad=0, xSize=0, ySize=0, gridreg::Bool=false, sds::Int=0, GMT=false)::NTuple{6, Float64}
494-
(GMT == 1 && isa(input, String)) && return vec(gmt_grdinfo_C(input).data)
497+
_getregion(input, Int(pad), Int(xSize), Int(ySize), gridreg==1, sds, GMT==1)
498+
end
499+
function _getregion(@nospecialize(input), pad::Int, xSize::Int, ySize::Int, gridreg::Bool, sds::Int, GMT::Bool)::NTuple{6, Float64}
500+
(GMT && isa(input, String)) && return vec(gmt_grdinfo_C(input).data)
495501
dataset = gd2gmt_helper(input, sds; short=true)[1]
496502
(xSize == 0) && (xSize = Gdal.width(dataset))
497503
(ySize == 0) && (ySize = Gdal.height(dataset))

src/mgd77/magref.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function magref_helper(cmd0::String, arg1; kwargs...)::Union{GDtype, GMTgrid, St
4040
end
4141

4242
# ---------------------------------------------------------------------------------------------------
43-
function magref_helper(arg1::GDtype, d::Dict{Symbol,Any})
43+
function magref_helper(@nospecialize(arg1::GDtype), d::Dict{Symbol,Any})
4444

4545
cmd = parse_common_opts(d, "", [:V_params :bi :f :hi :o :yx])[1]
4646
cmd = parse_these_opts(cmd, d, [[:C :cm4file], [:D :dstfile], [:E :f107file]])

src/utils.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,8 @@ parkermag(x, y, z=""; kw...) =
16971697
printstyled("\tTo use this function you need to load the FFTW package first. Do:\n\tusing FFTW"; color=:yellow)
16981698
parkergrav(x, y=""; kw...) =
16991699
printstyled("\tTo use this function you need to load the FFTW package first. Do:\n\tusing FFTW"; color=:yellow)
1700+
ppdrc(x; kw...) =
1701+
printstyled("\tTo use this function you need to load the FFTW package first. Do:\n\tusing FFTW"; color=:yellow)
17001702

17011703
read_xls(x; kw...) =
17021704
printstyled("\tTo use this function you need to load the XLSX package first. Do:\n\tusing XLSX"; color=:yellow)

src/utils_types.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,10 @@ If 'ind=0' append 'mat' at the end of 'D'
488488
If 'mat' is a vector optionally use the 'name' for the new inserted column
489489
If 'mat' is a matrix optionally use a 'names' vector (must have size(mat,2) elements) of new column names.
490490
"""
491-
function add2ds!(D::GMTdataset{T,2}, mat, ind::Int=0; name::AbstractString="", names::Vector{<:AbstractString}=AbstractString[]) where {T<:Real}
491+
function add2ds!(D::GMTdataset, mat, ind::Int=0; name::AbstractString="", names::Vector{<:AbstractString}=AbstractString[])
492+
_add2ds_1(D, mat, ind, name, names)
493+
end
494+
function _add2ds_1(@nospecialize(D), @nospecialize(mat), ind::Int, name::AbstractString, names::Vector{<:AbstractString})
492495
(isvector(mat) && size(D,1) != length(mat)) && error("Number of rows in GMTdataset and adding vector elements do not match.")
493496
(isa(mat, Matrix) && size(mat,1) > 1 && size(D,1) != size(mat,1)) && error("Number of rows in GMTdataset and adding matrix do not match.")
494497
n_newCols = isvector(mat) ? 1 : size(mat,2)
@@ -522,7 +525,7 @@ function add2ds!(D::Vector{<:GMTdataset}, mat, ind::Int=0; name::AbstractString=
522525
end
523526

524527
# ---------------------------------------------------------------------------------------------------
525-
function add2ds!(D::GMTdataset{T,2}; name::AbstractString="", names::Vector{<:AbstractString}=AbstractString[]) where {T<:Real}
528+
function add2ds!(@nospecialize(D::GMTdataset); name::AbstractString="", names::Vector{<:AbstractString}=AbstractString[])
526529
# Method for fixing the colnames and/or the bbox in DS that had their matrix extended.
527530
# 'name' and 'names' are only usable if 'D' already has 'colnames'
528531
isempty(D.colnames) && (D.colnames = [string("Col.",k) for k=1:size(D,2)])

0 commit comments

Comments
 (0)