From: Robert Klemme Date: 2009-11-10T06:25:08+09:00 Subject: Re: FileString - request for comments On 09.11.2009 17:29, apeiros@gmx.net wrote: > -------- Original-Nachricht -------- >> Von: Robert Klemme > As all highlevel things. If you don't know the things you're dealing with you can easily kill performance. Consider e.g. ary.any? { |obj| other.include?(obj) } - there, just accidentally created an O(n^2) algorithm. It can happen everywhere and it can look totally innocent. > That's not a problem that's specific to FileString but to everything that's abstract. True. >> And although at a certain level of abstraction a file and a >> String are pretty much the same (sequence of chars / bytes) it may >> actually be a good thing to keep the API separate in order to treat >> both appropriately. Stefan, what's your experience? > > As you see, I disagree :) > However, what you say is of course correct. Using FileString means you > have to keep in mind that you're dealing with a file. > But: if you know you're dealing with a file, it can even help you > making things faster. For example, if you indeed want to compare two > files for equality, FileString#== will be faster and less memory > intensive than you doing File.read(a) == File.read(b) if the two files > are big. A good point! You're probably right and I was too pessimistic. I'd love to see fs[/foo(\w+)/, 1] = "bar" fs.gsub! /foo/, "bar" etc. because those would be the ones that would make FileString convenient for me. :-) > Thanks for your thoughts robert, much appreciated Thanks for listening and sharing! Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/