Skip to content

Commit 0a5364a

Browse files
committed
improve performance
1 parent ea1f84d commit 0a5364a

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/dataset/modify.jl

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -311,31 +311,25 @@ function modify!(ds::AbstractDataset, @nospecialize(args...); threads::Bool = tr
311311
end
312312
end
313313

314-
# we must take care of all possible types, because, catching is very expensive
314+
# we must take care of all possible types, because, fallback is slow
315315
_is_scalar(::T, sz) where T <: Number = true
316316
_is_scalar(::Missing, sz) = true
317317
_is_scalar(::T, sz) where T <: Tuple = true
318318
_is_scalar(::TimeType, sz) = true
319319
_is_scalar(::T, sz) where T <: AbstractString = true
320320
_is_scalar(x::T, sz) where T <: AbstractVector = length(x) != sz
321-
function _is_scalar(_res, sz)
321+
322+
# TODO can we memorise this and avoid calling it repeatedly in a sesssion
323+
_is_scalar_barrier(::Val{T}) where T = hasmethod(size, (T,))
324+
325+
function _is_scalar(_res::T, sz) where T
322326
resize_col = false
323-
try
324-
size(_res)
327+
if _is_scalar_barrier(Val(T))
325328
if size(_res) == () || size(_res,1) != sz
326-
# fill!(allocatecol(typeof(_res), nrow(ds)),
327-
# _res)
328-
# _res = repeat([_res], nrow(ds))
329329
resize_col = true
330330
end
331-
catch e
332-
if (e isa MethodError)
333-
# fill!(allocatecol(typeof(_res), nrow(ds)),
334-
# _res)
335-
# _res = repeat([_res], nrow(ds))
336-
resize_col = true
337-
end
338-
331+
else
332+
resize_col = true
339333
end
340334
return resize_col
341335
end

0 commit comments

Comments
 (0)