Skip to content

Commit

Permalink
Merge pull request #678 from Shopify/require-unless-defined
Browse files Browse the repository at this point in the history
Don't call `Kernel#require` in hot loop
  • Loading branch information
tenderlove authored Jul 19, 2024
2 parents be0ba74 + 06db36f commit 6bb8d08
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/psych/scalar_scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module Psych
###
# Scan scalars for built in types
class ScalarScanner
autoload :Date, "date"

# Taken from http://yaml.org/type/timestamp.html
TIME = /^-?\d{4}-\d{1,2}-\d{1,2}(?:[Tt]|\s+)\d{1,2}:\d\d:\d\d(?:\.\d*)?(?:\s*(?:Z|[-+]\d{1,2}:?(?:\d\d)?))?$/

Expand Down Expand Up @@ -61,7 +63,6 @@ def tokenize string
string
end
elsif string.match?(/^\d{4}-(?:1[012]|0\d|\d)-(?:[12]\d|3[01]|0\d|\d)$/)
require 'date'
begin
class_loader.date.strptime(string, '%F', Date::GREGORIAN)
rescue ArgumentError
Expand Down

0 comments on commit 6bb8d08

Please sign in to comment.