Commit 1cc26e0f authored by Grzegorz Bizon's avatar Grzegorz Bizon

Improve performance of `StringPath`

parent bd4899be
......@@ -5,15 +5,15 @@ module Gitlab
# This is IO-operations safe class, that does similar job to
# Ruby's Pathname but without the risk of accessing filesystem.
#
# TODO: better support for './' and '../'
# TODO: better support for '../' and './'
#
class StringPath
attr_reader :path, :universe
def initialize(path, universe)
@path = prepare(path)
@universe = universe.map { |entry| prepare(entry) }
@universe.unshift('./') unless @universe.include?('./')
@universe = Set.new(universe.map { |entry| prepare(entry) })
@universe.add('./')
end
def to_s
......@@ -64,7 +64,10 @@ module Gitlab
end
def children
descendants.select { |descendant| descendant.parent == self }
return [] unless directory?
return @children if @children
children = @universe.select { |entry| entry =~ %r{^#{@path}[^/]+/?$} }
@children = children.map { |path| new(path) }
end
def directories
......@@ -85,6 +88,10 @@ module Gitlab
@path == other.path && @universe == other.universe
end
def inspect
"#{self.class.name}: #{@path}"
end
private
def new(path)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment