Re: Inserting to a sequence
- Posted by Robert Craig <rds at ATTCANADA.NET> Jul 31, 1999
- 440 views
Gabriel Boehme writes: > What is the fastest way of inserting an item into > a sequence? I know ED.EX uses the following > two methods: >1) For inserting a char into a line: > line = line[1..b_col-1] & char & line[b_col..length(line)] > 2) For inserting a line into a file: > buffer = append(buffer, 0) > for i = length(buffer)-1 to b_line by -1 do > buffer[i+1] = buffer[i] > end for > buffer[b_line] = line Method 1 is the simplest, and it's what I originally used for inserting a line. As I recall, I switched to method 2 a few years ago, after running out of memory at this exact point, while editing a huge file. Method 2 needs less memory, i.e. temp space, so I thought it might help. In fact it doesn't really help much but I left it that way. Method 2 might be faster than method 1, depending on the size of the sequence. Provided the sequence is reasonably long, you can make method 2 even faster if you replace for ... end for with: buffer[bline+1..length(buffer)] = buffer[bline..length(buffer)-1] The performance of ed depends mainly on the screen-writing operations, not the buffer manipulations. Regards, Rob Craig Rapid Deployment Software http://members.aol.com/FilesEu/