*** ./kate/document/katebuffer.cpp.old	2009-10-24 16:35:24.000000000 +0900
--- ./kate/document/katebuffer.cpp	2009-10-24 17:40:16.000000000 +0900
***************
*** 98,103 ****
--- 98,106 ----
        , m_eol (-1) // no eol type detected atm
        , m_file (filename)
        , m_buffer (qMin (m_file.size() == 0 ? KATE_FILE_LOADER_BS : m_file.size(), KATE_FILE_LOADER_BS), 0) // handle zero sized files special, like in /proc
+ #ifndef	ORIGINAL_CODE
+       , m_resbytes (0)
+ #endif
      {
      }
  
***************
*** 113,119 ****
--- 116,126 ----
      {
        if (m_file.open (QIODevice::ReadOnly))
        {
+ #ifdef	ORIGINAL_CODE
          int c = m_file.read (m_buffer.data(), m_buffer.size());
+ #else
+         int c = read_linewise();
+ #endif
  
          if (c > 0)
          {
***************
*** 280,286 ****
--- 287,297 ----
            // try to load more text if something is around
            if (!m_eof)
            {
+ #ifdef	ORIGINAL_CODE
              int c = m_file.read (m_buffer.data(), m_buffer.size());
+ #else
+             int c = read_linewise();
+ #endif
  
              // kill the old lines...
              m_text.remove (0, m_lastLineStart);
***************
*** 391,396 ****
--- 402,447 ----
      QFile m_file;
      QByteArray m_buffer;
      QString m_text;
+ #ifndef	ORIGINAL_CODE
+     QByteArray m_res;
+     int m_resbytes;
+ #endif
+ 
+ #ifndef	ORIGINAL_CODE
+     int read_linewise()
+     {
+         int count = 0;
+ 	if (m_resbytes > 0)
+ 	{
+ 		m_buffer.replace(0, m_resbytes, m_res);
+ 		count += m_resbytes;
+ 		m_resbytes = 0;
+ 	}
+ 
+         int error = m_file.read (m_buffer.data() + count, 
+ 			         m_buffer.size() - count);
+ 	if (error >= 0)
+ 		count += error;	
+ 	if (count == m_buffer.size())
+ 	{
+ 		int i;
+ 	        char *p = m_buffer.data(); 
+ 		for (i = count - 1;
+ 		     i >= 0 && p[i] != '\r' && p[i] != '\n' && p[i] != 0; i --)
+ 			;
+ 		if (i >= 0 && i < count - 1)
+ 		{
+ 			m_res = m_buffer.mid(i+1);
+ 			m_resbytes = count - i - 1;
+ 			count -= m_resbytes;
+ 		}
+ 	}
+ 
+ 	if (count > 0)
+ 		return count;
+ 	return error;
+      }
+ #endif
  };
  
  /**
