module DAV
  class Children < Struct.new(:parent)
    include DAV
    attr_reader :uris

    SEPARATOR = "\n"

    def initialize(parent)
      super parent
      load_paths
    end

    def store
      return unless changed?

      unless @uris.empty?
        relation_storage.set parent.id, @uris.join(SEPARATOR)
      else
        relation_storage.delete parent.id
      end

      reset!

      return true
    end

    def add(child)
      @uris.push child.decoded_uri
      changed!
      self
    end
    def remove(child)
      @uris.delete_if { |uri| uri == child.decoded_uri }
      changed!
      self
    end

    def each
      if block_given?
        @uris.each { |uri| yield parent.join(uri.path) }
      else
        Enumerator.new self, :each
      end
    end

    protected

      attr_reader :changed
      alias changed? changed
      def changed!
        @changed = true
      end
      def reset!
        @changed = false
      end

      def load_paths
        string   = relation_storage.get parent.id
        string ||= ''

        @uris = string.split(SEPARATOR).map { |uri| URI.parse uri }
      end

  end
end

require 'set'

module DAV
  class Children < Struct.new(:parent)
    include DAV
    attr_reader :uris

    SEPARATOR = "\n"

    def initialize(parent)
      super parent
      load_paths
    end

    def store
      return unless changed?

      unless @uris.empty?
        relation_storage.set parent.id, @uris.to_a.join(SEPARATOR)
      else
        relation_storage.delete parent.id
      end

      reset!

      return true
    end

    def add(child)
      @uris.add child.decoded_uri
      changed!
      self
    end
    def remove(child)
      @uris.delete_if { |uri| uri == child.decoded_uri }
      changed!
      self
    end

    def each
      if block_given?
        @uris.each { |uri| yield parent.join(uri.path) }
      else
        Enumerator.new self, :each
      end
    end

    protected

      attr_reader :changed
      alias changed? changed
      def changed!
        @changed = true
      end
      def reset!
        @changed = false
      end

      def load_paths
        string   = relation_storage.get parent.id
        string ||= ''

        @uris = Set.new string.split(SEPARATOR).map { |uri| URI.parse uri }
      end

  end
end

Use a set instead of simple array.
Use a set instead of simple array.
