aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1996-07-30 18:51:50 +0000
committerRichard M. Stallman1996-07-30 18:51:50 +0000
commit6fec5601a25f970f3f03b591c297b3521fd22243 (patch)
treec3268246c48ac68ab30613f0d0be18da4f962560 /src
parent3b9792585175a2b286024337d3bb31878d6e72d2 (diff)
downloademacs-6fec5601a25f970f3f03b591c297b3521fd22243.tar.gz
emacs-6fec5601a25f970f3f03b591c297b3521fd22243.zip
When printing into a buffer, generate all the text
first, then insert it all at once. (print_buffer): New variable. (print_buffer_size, print_buffer_pos): New variables. (PRINTPREPARE): Allocate print_buffer. (PRINTFINISH): Free print_buffer after inserting its contents. (printchar, strout): Output into print_buffer. (print_string): If printcharfun is nil, use strout.
Diffstat (limited to 'src')
-rw-r--r--src/print.c54
1 files changed, 40 insertions, 14 deletions
diff --git a/src/print.c b/src/print.c
index 62a679cc81c..ebfb7715199 100644
--- a/src/print.c
+++ b/src/print.c
@@ -50,6 +50,15 @@ int print_depth;
50#define PRINT_CIRCLE 200 50#define PRINT_CIRCLE 200
51Lisp_Object being_printed[PRINT_CIRCLE]; 51Lisp_Object being_printed[PRINT_CIRCLE];
52 52
53/* When printing into a buffer, first we put the text in this
54 block, then insert it all at once. */
55char *print_buffer;
56
57/* Size allocated in print_buffer. */
58int print_buffer_size;
59/* Size used in print_buffer. */
60int print_buffer_pos;
61
53/* Maximum length of list to print in full; noninteger means 62/* Maximum length of list to print in full; noninteger means
54 effectively infinity */ 63 effectively infinity */
55 64
@@ -158,9 +167,20 @@ glyph_to_str_cpy (glyphs, str)
158 old_point = point; \ 167 old_point = point; \
159 SET_PT (marker_position (printcharfun)); \ 168 SET_PT (marker_position (printcharfun)); \
160 start_point = point; \ 169 start_point = point; \
161 printcharfun = Qnil;} 170 printcharfun = Qnil;} \
171 if (NILP (printcharfun)) \
172 { \
173 print_buffer_pos = 0; \
174 print_buffer_size = 1000; \
175 print_buffer = (char *) xmalloc (print_buffer_size); \
176 } \
177 else \
178 print_buffer = 0;
162 179
163#define PRINTFINISH \ 180#define PRINTFINISH \
181 if (NILP (printcharfun)) \
182 insert (print_buffer, print_buffer_pos); \
183 if (print_buffer) free (print_buffer); \
164 if (MARKERP (original)) \ 184 if (MARKERP (original)) \
165 Fset_marker (original, make_number (point), Qnil); \ 185 Fset_marker (original, make_number (point), Qnil); \
166 if (old_point >= 0) \ 186 if (old_point >= 0) \
@@ -189,7 +209,10 @@ printchar (ch, fun)
189 if (EQ (fun, Qnil)) 209 if (EQ (fun, Qnil))
190 { 210 {
191 QUIT; 211 QUIT;
192 insert (&ch, 1); 212 if (print_buffer_pos == print_buffer_size)
213 print_buffer = (char *) xrealloc (print_buffer,
214 print_buffer_size *= 2);
215 print_buffer[print_buffer_pos++] = ch;
193 return; 216 return;
194 } 217 }
195 218
@@ -239,10 +262,21 @@ strout (ptr, size, printcharfun)
239 262
240 if (EQ (printcharfun, Qnil)) 263 if (EQ (printcharfun, Qnil))
241 { 264 {
242 insert (ptr, size >= 0 ? size : strlen (ptr)); 265 if (size < 0)
266 size = strlen (ptr);
267
268 if (print_buffer_pos + size > print_buffer_size)
269 {
270 print_buffer_size = print_buffer_size * 2 + size;
271 print_buffer = (char *) xrealloc (print_buffer,
272 print_buffer_size);
273 }
274 bcopy (ptr, print_buffer + print_buffer_pos, size);
275 print_buffer_pos += size;
276
243#ifdef MAX_PRINT_CHARS 277#ifdef MAX_PRINT_CHARS
244 if (max_print) 278 if (max_print)
245 print_chars += size >= 0 ? size : strlen(ptr); 279 print_chars += size;
246#endif /* MAX_PRINT_CHARS */ 280#endif /* MAX_PRINT_CHARS */
247 return; 281 return;
248 } 282 }
@@ -301,17 +335,9 @@ print_string (string, printcharfun)
301 Lisp_Object string; 335 Lisp_Object string;
302 Lisp_Object printcharfun; 336 Lisp_Object printcharfun;
303{ 337{
304 if (EQ (printcharfun, Qt)) 338 if (EQ (printcharfun, Qt) || NILP (printcharfun))
305 /* strout is safe for output to a frame (echo area). */ 339 /* strout is safe for output to a frame (echo area) or to print_buffer. */
306 strout (XSTRING (string)->data, XSTRING (string)->size, printcharfun); 340 strout (XSTRING (string)->data, XSTRING (string)->size, printcharfun);
307 else if (EQ (printcharfun, Qnil))
308 {
309#ifdef MAX_PRINT_CHARS
310 if (max_print)
311 print_chars += XSTRING (string)->size;
312#endif /* MAX_PRINT_CHARS */
313 insert_from_string (string, 0, XSTRING (string)->size, 1);
314 }
315 else 341 else
316 { 342 {
317 /* Otherwise, fetch the string address for each character. */ 343 /* Otherwise, fetch the string address for each character. */