× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Thu, 2005-10-20 at 15:31 -0500, albartell wrote:
> Hi  y'all,
>  
> I am trying to find the fastest way to go through a text IFS file and
> replace all occurrences of a string. The file sizes that I am working with
> range from less then 200 bytes to over 80Kb. Obviously the 80Kb one is
> causing the slowness problems that I want to try and remedy.  
Hmm, it seems there is a bug.  If the data you are looking for crosses a
block boundary, your code is not catching it.  For example, assume the
end of a 60000 byte block looks like '&qu' and the beginning of the next
block is 'ot;', then you would not be replacing the &quot with the '"'.

>  
> Below is what I am doing essentially. It only takes two reads from the IFS
> file to get all of the data, but I was wondering if there is any way to do a
> find and replace faster on that large of a string (65535 varying)?
Your current routine scans the buffer six times.  Three of those (half!)
start with the same character.  If there isn't a '&', then some of the
searches could be avoided.

I haven't had to build or locate a very speedy search and replace, but I
would investigate pulling the entire file into memory (assuming it will
always fit inside 16Mb), then write it out, translating by brute force. 

If that's not fast enough, another possibility would be to investigate
the standard C library.  You might be able to whip up a nice search and
replace function using memcpy and memcmp.

"Algorithms in C" by Robert Sedgewick has some interesting string search
routines.

There are probably some MI functions as well.


Regards,
Rich


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.