From: Kevin Howe Date: 2004-09-17T12:14:49+09:00 Subject: Re: Tidy binding using DL > You are much better off doing: > buffer = ' ' * 8192 > This way you don't invoke a method 8192 times. Point taken! The buffer has another issue though - setting the buffer to a fixed number such as 1024 will eventually cause a problem. This happens as soon as the tidy output exceeds the given size (1024), and the result is an empty buffer. Even setting to a larger fixed number is pointless since eventually data may be produced which exceeds that amount. One solution is to generate a size based on the given data. In my current version I've changed save_string to accept a second parameter which specifies buffer length. I then pass the length of the given html string multiplied by 10 to get a buffer length that will always be long enough (In testing *6 still produced problems, *10 always provided enough space). Example: def save_string(doc, buflen) buffer = " " * buflen rt = tidySaveString(doc, buffer, buflen) len = @args[2] str = @args[1] str[0,len] end save_string(doc, str.length*10) # where str is the given html string to be tidied