1

I created a notepad++ plugin in C++.It searches between a keyword in a Log file and copy the entire data between this keyword.(This keyword occurs exactly two times in the file or does not occur at all). Here is my code

        std::ifstream in(curr_file_path);
        std::string search("TEXT TO SEARCH");
  while (std::getline(in, line))
     {
        r_val = line.find(search);
        if (r_val != -1)
        {
            f_match = r_val;
            r_val = -1;
            while (r_val == -1)
            {
                std::getline(in, line);
                r_val = line.find(search);
                for (int i = 0; i < line.size(); i++)
                {
                    pDestText[textLen++] = line[i];

                }
            }
            pDestText[textLen - 27] = '\0';
            break;
        }
    }
 }

search is the string to be searched.Input file is in. My query is as the log file is very large ,it is taking time around 5 seconds.Can i optimise This .One optimization which I am thinking is skip first 50000 lines of code as I am sure that the text I am looking wont come in first 50000 lines.But is there any better way of optimization.If not ,can anyone tell how to skip first 50000 lines of code and throw a error if it has less than 50000 lines.

somerandomguy
  • 323
  • 4
  • 13

1 Answers1

0

In searching i suggest you use an algorithm that will suit your needs

http://bigocheatsheet.com/

try to look at this link as this may help you on what to choose. there is always a pros and cons on what algorithm you will use. you can also combine two or more algorithm or even make your own if you think that it will be much more optimize than the listed.