Skip to content

Commit c468e6f

Browse files
mobereggerahx
authored andcommitted
Optimize FindContent#call
1 parent 1a86f55 commit c468e6f

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

lib/openapi_first/router/find_content.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ def self.call(contents, content_type)
88
return contents[nil] if content_type.nil? || content_type.empty?
99

1010
contents.fetch(content_type) do
11-
type = content_type.split(';')[0]
12-
contents[type] || contents["#{type.split('/')[0]}/*"] || contents['*/*'] || contents[nil]
11+
semi = content_type.index(';')
12+
type = semi ? content_type[0, semi] : content_type
13+
slash = type.index('/') || type.length
14+
contents[type] || contents["#{type[0, slash]}/*"] || contents['*/*'] || contents[nil]
1315
end
1416
end
1517
end

0 commit comments

Comments
 (0)