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.