aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
authorDmitry Antipov2013-10-08 10:40:09 +0400
committerDmitry Antipov2013-10-08 10:40:09 +0400
commitf8498081911e4c1381c4bed5ac3b664ceca57d64 (patch)
treed96b7bf86daef23ecae0f9239ef79bff81500490 /src/coding.c
parentb7d5bd823c239a8ee3613abcc4e24fe290a673d0 (diff)
downloademacs-f8498081911e4c1381c4bed5ac3b664ceca57d64.tar.gz
emacs-f8498081911e4c1381c4bed5ac3b664ceca57d64.zip
Do not allocate huge temporary memory areas and objects while encoding
for file I/O, thus reducing an enormous memory usage for large buffers. See http://lists.gnu.org/archive/html/emacs-devel/2013-10/msg00180.html. * coding.h (struct coding_system): New member raw_destination. * coding.c (setup_coding_system): Initialize it to zero. (encode_coding_object): If raw_destination is set, do not create dst_object. Add comment. * fileio.c (toplevel): New constant E_WRITE_MAX. (e_write): Do not encode more than E_WRITE_MAX characters per one loop iteration. Use raw_destination if E_WRITE_MAX characters is encoded.
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/coding.c b/src/coding.c
index c10fb375672..ac828a48683 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -5761,6 +5761,7 @@ setup_coding_system (Lisp_Object coding_system, struct coding_system *coding)
5761 coding->safe_charsets = SDATA (val); 5761 coding->safe_charsets = SDATA (val);
5762 coding->default_char = XINT (CODING_ATTR_DEFAULT_CHAR (attrs)); 5762 coding->default_char = XINT (CODING_ATTR_DEFAULT_CHAR (attrs));
5763 coding->carryover_bytes = 0; 5763 coding->carryover_bytes = 0;
5764 coding->raw_destination = 0;
5764 5765
5765 coding_type = CODING_ATTR_TYPE (attrs); 5766 coding_type = CODING_ATTR_TYPE (attrs);
5766 if (EQ (coding_type, Qundecided)) 5767 if (EQ (coding_type, Qundecided))
@@ -8352,6 +8353,11 @@ encode_coding_object (struct coding_system *coding,
8352 { 8353 {
8353 if (BUFFERP (coding->dst_object)) 8354 if (BUFFERP (coding->dst_object))
8354 coding->dst_object = Fbuffer_string (); 8355 coding->dst_object = Fbuffer_string ();
8356 else if (coding->raw_destination)
8357 /* This is used to avoid creating huge Lisp string.
8358 NOTE: caller who sets `raw_destination' is also
8359 responsible for freeing `destination' buffer. */
8360 coding->dst_object = Qnil;
8355 else 8361 else
8356 { 8362 {
8357 coding->dst_object 8363 coding->dst_object