nickbnf / glogg

A fast, advanced log explorer.
http://glogg.bonnefon.org/
GNU General Public License v3.0
1.17k stars 368 forks source link

Eagerly fill LogFilteredData::filteredItemsCache_ #224

Open gin-ahirsch opened 6 years ago

gin-ahirsch commented 6 years ago

I fixed some issues with the last commit. It actually builds now :)

gin-ahirsch commented 6 years ago

Rebased with the following diff:

+diff --git a/src/data/logfiltereddata.cpp b/src/data/logfiltereddata.cpp
index 59bcc93..cc231ef 100644
--- a/src/data/logfiltereddata.cpp
+++ b/src/data/logfiltereddata.cpp
@@ -258,7 +258,7 @@ void LogFilteredData::updateMaxLengthMarks( qint64 removed_line )
     if ( sourceLogData_->getLineLength( removed_line ) >= maxLengthMarks_ ) {
         LOG(logDEBUG) << "deleteMark recalculating longest mark";
         maxLengthMarks_ = 0;
-        for ( auto &mark : marks_ ) {
+        for ( auto& mark : marks_ ) {
             LOG(logDEBUG) << "line " << mark.lineNumber();
             maxLengthMarks_ = qMax( maxLengthMarks_,
                     sourceLogData_->getLineLength( mark.lineNumber() ) );
@@ -286,6 +286,10 @@ void LogFilteredData::setVisibility( Visibility visi )
 //
 void LogFilteredData::handleSearchProgressed( int nbMatches, int progress, qint64 initial_position )
 {
+    using std::begin;
+    using std::end;
+    using std::next;
+
     LOG(logDEBUG) << "LogFilteredData::handleSearchProgressed matches="
         << nbMatches << " progress=" << progress;

@@ -483,6 +487,10 @@ void LogFilteredData::regenerateFilteredItemsCache() const

 void LogFilteredData::insertIntoFilteredItemsCache( size_t insert_index, FilteredItem item )
 {
+    using std::begin;
+    using std::end;
+    using std::next;
+
     if ( visibility_ != MarksAndMatches ) {
         // this is invalidated and will be regenerated when we need it
         filteredItemsCache_.clear();
@@ -491,7 +499,7 @@ void LogFilteredData::insertIntoFilteredItemsCache( size_t insert_index, Filtere

     // Search for the corresponding index.
     // We can start the search from insert_index, since lineNumber >= index is always true.
-    auto found = lower_bound( next( begin( filteredItemsCache_ ), insert_index ), end( filteredItemsCache_ ), item );
+    auto found = std::lower_bound( next( begin( filteredItemsCache_ ), insert_index ), end( filteredItemsCache_ ), item );
     if ( found == end( filteredItemsCache_ ) || found->lineNumber() > item.lineNumber() ) {
         filteredItemsCache_.insert( found, item );
     } else {
@@ -507,6 +515,10 @@ void LogFilteredData::insertIntoFilteredItemsCache( FilteredItem item )

 void LogFilteredData::insertMatchesIntoFilteredItemsCache( size_t start_index )
 {
+    using std::begin;
+    using std::end;
+    using std::next;
+
     assert( start_index <= matching_lines_.size() );

     if ( visibility_ != MarksAndMatches ) {
@@ -526,7 +538,7 @@ void LogFilteredData::insertMatchesIntoFilteredItemsCache( size_t start_index )
     auto filteredIt = next( begin( filteredItemsCache_ ), start_index );
     for ( auto matchesIt = next( begin( matching_lines_ ), start_index ); matchesIt != end( matching_lines_ ); ++matchesIt ) {
         FilteredItem item{ matchesIt->lineNumber(), Match };
-        filteredIt = lower_bound( filteredIt, end( filteredItemsCache_ ), item );
+        filteredIt = std::lower_bound( filteredIt, end( filteredItemsCache_ ), item );
         if ( filteredIt == end( filteredItemsCache_ ) || filteredIt->lineNumber() > item.lineNumber() ) {
             filteredIt = filteredItemsCache_.insert( filteredIt, item );
         } else {
@@ -538,6 +550,11 @@ void LogFilteredData::insertMatchesIntoFilteredItemsCache( size_t start_index )

 void LogFilteredData::removeFromFilteredItemsCache( size_t remove_index, FilteredItem item )
 {
+    using std::begin;
+    using std::distance;
+    using std::end;
+    using std::next;
+
     if ( visibility_ != MarksAndMatches ) {
         // this is invalidated and will be regenerated when we need it
         filteredItemsCache_.clear();
@@ -547,7 +564,7 @@ void LogFilteredData::removeFromFilteredItemsCache( size_t remove_index, Filtere

     // Search for the corresponding index.
     // We can start the search from remove_index, since lineNumber >= index is always true.
-    auto found = equal_range( next( begin( filteredItemsCache_ ), remove_index ), end( filteredItemsCache_ ), item );
+    auto found = std::equal_range( next( begin( filteredItemsCache_ ), remove_index ), end( filteredItemsCache_ ), item );
     if( found.first == end( filteredItemsCache_ ) ) {
         LOG(logERROR) << "Attempt to remove line " << item.lineNumber() << " from filteredItemsCache_ failed, since it was not found";
         return;
@@ -565,6 +582,9 @@ void LogFilteredData::removeFromFilteredItemsCache( size_t remove_index, Filtere

 void LogFilteredData::removeAllFromFilteredItemsCache( FilteredLineType type )
 {
+    using std::begin;
+    using std::end;
+
     if ( visibility_ != MarksAndMatches ) {
         // this is invalidated and will be regenerated when we need it
         filteredItemsCache_.clear();
@@ -572,6 +592,6 @@ void LogFilteredData::removeAllFromFilteredItemsCache( FilteredLineType type )
         return;
     }

-    auto erase_begin = remove_if( begin( filteredItemsCache_ ), end( filteredItemsCache_ ), [type]( FilteredItem& item ) { return !item.remove( type ); } );
+    auto erase_begin = std::remove_if( begin( filteredItemsCache_ ), end( filteredItemsCache_ ), [type]( FilteredItem& item ) { return !item.remove( type ); } );
     filteredItemsCache_.erase( erase_begin, end( filteredItemsCache_ ) );
 }
diff --git a/src/data/logfiltereddata.h b/src/data/logfiltereddata.h
index 880182d..7eca098 100644
--- a/src/data/logfiltereddata.h
+++ b/src/data/logfiltereddata.h
@@ -181,19 +181,19 @@ class LogFilteredData : public AbstractLogData {
     void updateMaxLengthMarks( qint64 removed_line );
 };

-static LogFilteredData::FilteredLineType& operator|=(LogFilteredData::FilteredLineType& a, LogFilteredData::FilteredLineType b)
+inline LogFilteredData::FilteredLineType& operator|=(LogFilteredData::FilteredLineType& a, LogFilteredData::FilteredLineType b)
 {
     a = LogFilteredData::FilteredLineType( a | b );
     return a;
 }

-static LogFilteredData::FilteredLineType& operator&=(LogFilteredData::FilteredLineType& a, LogFilteredData::FilteredLineType b)
+inline LogFilteredData::FilteredLineType& operator&=(LogFilteredData::FilteredLineType& a, LogFilteredData::FilteredLineType b)
 {
     a = LogFilteredData::FilteredLineType( a & b );
     return a;
 }

-static LogFilteredData::FilteredLineType operator~(LogFilteredData::FilteredLineType a)
+inline LogFilteredData::FilteredLineType operator~(LogFilteredData::FilteredLineType a)
 {
     return LogFilteredData::FilteredLineType( ~static_cast<int>( a ) );
 }