}
/// Reads one line from filebuffer and inserts to textbuffer
-void CMergeDoc::CDiffTextBuffer::ReadLineFromBuffer(TCHAR *lpLineBegin, DWORD dwLineLen /* =0 */)
+void CMergeDoc::CDiffTextBuffer::ReadLineFromBuffer(TCHAR *lpLineBegin, DWORD dwLineNum, DWORD dwLineLen /* =0 */)
{
if (m_nSourceEncoding >= 0)
iconvert (lpLineBegin, m_nSourceEncoding, 1, m_nSourceEncoding == 15);
- InsertLine(lpLineBegin, dwLineLen);
+ AppendLine(dwLineNum, lpLineBegin, dwLineLen);
}
/// Sets path for temporary files
MAPPEDFILEDATA fileData = {0};
CString sExt;
BOOL bSuccess = FALSE;
- BOOL nRetVal = FRESULT_OK;
+ int nRetVal = FRESULT_OK;
+ DWORD dwLines = 0;
// Set encoding based on extension, if we know one
SplitFilename(pszFileName, NULL, NULL, &sExt);
bSuccess = files_openFileMapped(&fileData);
if (bSuccess)
- nRetVal = files_binCheck(&fileData);
+ nRetVal = files_analyzeFile(&fileData, &dwLines);
else
nRetVal = FRESULT_ERROR;
ASSERT(nCrlfStyle >= 0 && nCrlfStyle <= 2);
SetCRLFMode(nCrlfStyle);
- m_aLines.SetSize(0, 4096);
+ m_aLines.SetSize(dwLines, 4096);
DWORD dwBytesRead = 0;
TCHAR *lpChar = (TCHAR *)fileData.pMapBase;
TCHAR *lpLineBegin = lpChar;
int eolChars = 0;
+ DWORD nLineNum = 0;
while (dwBytesRead < fileData.dwSize)
{
TCHAR c = *lpChar;
dwBytesRead++;
// This is an EOL
- ReadLineFromBuffer(lpLineBegin, lpChar - lpLineBegin);
+ ReadLineFromBuffer(lpLineBegin, nLineNum, lpChar - lpLineBegin);
+ nLineNum++;
lpLineBegin = lpChar;
continue;
}
// Handle case where file ended with line without EOL
if (lpChar > lpLineBegin)
// no ghost line, because that would append an EOL to the last line
- ReadLineFromBuffer(lpLineBegin, lpChar - lpLineBegin);
+ ReadLineFromBuffer(lpLineBegin, nLineNum, lpChar - lpLineBegin);
else
// Last line had EOL, so append succeeding ghost line
InsertLine(_T(""), 0);
CString m_strTempPath;
int DetermineCRLFStyle(LPVOID lpBuf, DWORD dwLength);
- void ReadLineFromBuffer(TCHAR *lpLineBegin, DWORD dwLineLen = 0);
+ void ReadLineFromBuffer(TCHAR *lpLineBegin, DWORD dwLineNum, DWORD dwLineLen = 0);
public :
void SetTempPath(CString path);
virtual void AddUndoRecord (BOOL bInsert, const CPoint & ptStartPos, const CPoint & ptEndPos,
* @note This function is safe: it first checks that there are unread bytes,
* @note so that we do not read past EOF
*/
-int files_readEOL(TCHAR *lpLineEnd, DWORD bytesLeft, BOOL bEOLSensitive)
+int files_readEOL(TBYTE *lpLineEnd, DWORD bytesLeft, BOOL bEOLSensitive)
{
int eolBytes = 0;
}
/**
- * @brief Checks memory-mapped file for a binary data
+ * @brief Checks Checks memory-mapped for binary data and counts lines
+ * in textfile.
* @note This does not work for UNICODE files
- * @note as WinMerge is not compiled UNICODE enabled
+ * as WinMerge is not compiled UNICODE enabled
*/
-int files_binCheck(MAPPEDFILEDATA *fileData)
+int files_analyzeFile(MAPPEDFILEDATA *fileData, DWORD * dwLineCount)
{
// Use unsigned type for binary compare
TBYTE *lpByte = (TBYTE *)fileData->pMapBase;
BOOL bBinary = FALSE;
DWORD dwBytesRead = 0;
+ *dwLineCount = 1;
while ((dwBytesRead < fileData->dwSize - 1) && (bBinary == FALSE))
{
if (*lpByte < 0x09)
{
bBinary = TRUE;
+ lpByte++;
+ dwBytesRead++;
+ }
+ else if (*lpByte == '\r' || *lpByte == '\n')
+ {
+ const int nEolBytes = files_readEOL(lpByte, fileData->dwSize - dwBytesRead, TRUE);
+ lpByte += nEolBytes;
+ dwBytesRead += nEolBytes; // Skip EOL chars
+ (*dwLineCount)++;
+ }
+ else
+ {
+ lpByte++;
+ dwBytesRead++;
}
- lpByte++;
- dwBytesRead++;
}
if (bBinary)
BOOL files_openFileMapped(MAPPEDFILEDATA *fileData);
BOOL files_closeFileMapped(MAPPEDFILEDATA *fileData, DWORD newSize, BOOL flush);
-int files_readEOL(TCHAR *lpLineEnd, DWORD bytesLeft, BOOL bEOLSensitive);
-int files_binCheck(MAPPEDFILEDATA *fileData);
+int files_readEOL(TBYTE *lpLineEnd, DWORD bytesLeft, BOOL bEOLSensitive);
+int files_analyzeFile(MAPPEDFILEDATA *fileData, DWORD * dwLineCount);
#endif // _FILES_H
\ No newline at end of file
+2003-08-31 Kimmo
+ PATCH: [ 797741 ] Faster file loading
+ WinMerge: files.h files.cpp MergeDoc.h MergeDoc.cpp
+
2003-08-30 Kimmo
PATCH: [ 797797 ] OnOptions must exchange diffOptions with the registry
Submitted by Laoran.
- WinMerge: MainFrm.cpp
+ WinMerge: MainFrm.cpp
2003-08-30 Laoran
PATCH: [ 784109 ] layout with two new horizontal panels