File indexing completed on 2024-05-05 05:53:47
0001 /* 0002 SPDX-FileCopyrightText: 1997, 1998 Lars Doelle <lars.doelle@on-line.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef HISTORYFILE_H 0008 #define HISTORYFILE_H 0009 0010 // Qt 0011 #include <QTemporaryFile> 0012 0013 #include "konsoleprivate_export.h" 0014 0015 namespace Konsole 0016 { 0017 /* 0018 An extendable tmpfile(1) based buffer. 0019 */ 0020 class HistoryFile 0021 { 0022 public: 0023 HistoryFile(); 0024 virtual ~HistoryFile(); 0025 0026 virtual void add(const char *buffer, qint64 count); 0027 virtual void get(char *buffer, qint64 size, qint64 loc); 0028 virtual void set(char *buffer, qint64 size, qint64 loc); 0029 virtual void removeLast(qint64 loc); 0030 virtual qint64 len() const; 0031 0032 // mmaps the file in read-only mode 0033 void map(); 0034 // un-mmaps the file 0035 void unmap(); 0036 0037 private: 0038 qint64 _length; 0039 QTemporaryFile _tmpFile; 0040 0041 // pointer to start of mmap'ed file data, or 0 if the file is not mmap'ed 0042 uchar *_fileMap; 0043 0044 // incremented whenever 'add' is called and decremented whenever 0045 //'get' is called. 0046 // this is used to detect when a large number of lines are being read and processed from the history 0047 // and automatically mmap the file for better performance (saves the overhead of many lseek-read calls). 0048 int _readWriteBalance; 0049 0050 // when _readWriteBalance goes below this threshold, the file will be mmap'ed automatically 0051 static const int MAP_THRESHOLD = -1000; 0052 }; 0053 0054 } 0055 0056 #endif