aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2013-01-21 13:13:23 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2013-01-21 13:52:36 +0100
commit821c61e9967e62fd81038e4b879c5452bffe2dfb (patch)
tree44d3eb0b5c47672e7b3ae2c6517fe1ef2a1109ce /src
parent3b33159a390722366a262517a6f96205a9df5c17 (diff)
downloadsciteco-821c61e9967e62fd81038e4b879c5452bffe2dfb.tar.gz
improved reading files by using memory-mapping
* file must be in primary memory for scintilla * we cannot write to scintilla's buffer memory directly * so mapping the file is best: in the best case it is not copied to primary memory and resides in kernel cache * in any case, mapping to memory is faster than read()ing into primary memory * copying from mapped virtual memory to scintilla buffer (via SCI_APPENDTEXT) is faster than copying from primary memory
Diffstat (limited to 'src')
-rw-r--r--src/ring.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/ring.cpp b/src/ring.cpp
index a7c3ebe..ed9e77c 100644
--- a/src/ring.cpp
+++ b/src/ring.cpp
@@ -105,21 +105,24 @@ Buffer::UndoTokenClose::run(void)
bool
Buffer::load(const gchar *filename)
{
- gchar *contents;
- gsize size;
+ GMappedFile *file;
+ gsize length;
- /* FIXME: prevent excessive allocations by reading file into buffer */
- if (!g_file_get_contents(filename, &contents, &size, NULL))
+ file = g_mapped_file_new(filename, FALSE, NULL);
+ if (!file)
return false;
+ length = g_mapped_file_get_length(file);
edit();
interface.ssm(SCI_BEGINUNDOACTION);
interface.ssm(SCI_CLEARALL);
- interface.ssm(SCI_APPENDTEXT, size, (sptr_t)contents);
+ if (length > 0)
+ interface.ssm(SCI_APPENDTEXT, length,
+ (sptr_t)g_mapped_file_get_contents(file));
interface.ssm(SCI_ENDUNDOACTION);
- g_free(contents);
+ g_mapped_file_unref(file);
/* NOTE: currently buffer cannot be dirty */
#if 0