Skip to content

Commit 643fe95

Browse files
committed
faster duplicate-checking in date parser
1 parent 714b6c1 commit 643fe95

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

base/dates/io.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,14 @@ SLOT_RULE['M'] = Minute
8181
SLOT_RULE['S'] = Second
8282
SLOT_RULE['s'] = Millisecond
8383

84-
duplicates(slots) = any(map(x->count(y->x.parser==y.parser,slots),slots) .> 1)
84+
function anyduplicates(slots)
85+
for i = 1:length(slots), j = i+1:length(slots)
86+
if slots[i].parser == slots[j].parser
87+
return true
88+
end
89+
end
90+
return false
91+
end
8592

8693
"""
8794
DateFormat(format::AbstractString, locale::AbstractString="english") -> DateFormat
@@ -130,7 +137,7 @@ function DateFormat(f::AbstractString, locale::AbstractString="english")
130137
push!(slots,slot)
131138
end
132139

133-
duplicates(slots) && throw(ArgumentError("Two separate periods of the same type detected"))
140+
anyduplicates(slots) && throw(ArgumentError("Two separate periods of the same type detected"))
134141
return DateFormat(slots,prefix,locale)
135142
end
136143

0 commit comments

Comments
 (0)