Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eagerly fill LogFilteredData::filteredItemsCache_ #224

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

gin-ahirsch
Copy link
Contributor

No description provided.

The line numbers will be int::max() if the iterators are at the end, so
we don't need to check the iterators here.
@gin-ahirsch gin-ahirsch force-pushed the eager-filtered-items-cache branch from 534fc4c to 3ed384d Compare June 21, 2018 08:04
@gin-ahirsch
Copy link
Contributor Author

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

@gin-ahirsch gin-ahirsch force-pushed the eager-filtered-items-cache branch from 3ed384d to 4d38f64 Compare June 21, 2018 09:39
and progressively fill/remove items instead of completely regenerating
the whole cache.
by passing in a guess for the index.
@gin-ahirsch gin-ahirsch force-pushed the eager-filtered-items-cache branch from 4d38f64 to 70538f4 Compare August 10, 2018 10:30
@gin-ahirsch
Copy link
Contributor Author

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 ) );
 }

@gin-ahirsch gin-ahirsch force-pushed the eager-filtered-items-cache branch from caf0e7b to b49a6a8 Compare March 4, 2019 15:50
@gin-ahirsch gin-ahirsch force-pushed the eager-filtered-items-cache branch from b49a6a8 to cc302f3 Compare March 4, 2019 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant