diff options
author | hunt <hunt> | 2007-11-12 21:57:31 +0000 |
---|---|---|
committer | hunt <hunt> | 2007-11-12 21:57:31 +0000 |
commit | 15e6cce92a4406ed68b4b0e57ec629ae4ddbd682 (patch) | |
tree | 9d2b5bd099a11e9acb9a161318f2b297d5ff0802 /runtime/print.c | |
parent | 32784362de8e2cfc686ce98557dd261003aff2ff (diff) | |
download | systemtap-steved-15e6cce92a4406ed68b4b0e57ec629ae4ddbd682.tar.gz systemtap-steved-15e6cce92a4406ed68b4b0e57ec629ae4ddbd682.tar.xz systemtap-steved-15e6cce92a4406ed68b4b0e57ec629ae4ddbd682.zip |
2007-11-12 Martin Hunt <hunt@redhat.com>
* print.c (_stp_print): Rewrite to eliminate the strlen()
call and save a bit of time.
Diffstat (limited to 'runtime/print.c')
-rw-r--r-- | runtime/print.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/runtime/print.c b/runtime/print.c index 326d67d5..a451f622 100644 --- a/runtime/print.c +++ b/runtime/print.c @@ -210,16 +210,26 @@ void _stp_printf (const char *fmt, ...) void _stp_print (const char *str) { - int num = strlen (str); _stp_pbuf *pb = per_cpu_ptr(Stp_pbuf, smp_processor_id()); - int size = STP_BUFFER_SIZE - pb->len; - if (unlikely(num >= size)) { + char *end = pb->buf + STP_BUFFER_SIZE; + char *ptr = pb->buf + pb->len; + char *instr = (char *)str; + + while (ptr < end && *instr) + *ptr++ = *instr++; + + /* Did loop terminate due to lack of buffer space? */ + if (unlikely(*instr)) { + /* Don't break strings across subbufs. */ + /* Restart after flushing. */ _stp_print_flush(); - if (num > STP_BUFFER_SIZE) - num = STP_BUFFER_SIZE; + end = pb->buf + STP_BUFFER_SIZE; + ptr = pb->buf + pb->len; + instr = (char *)str; + while (ptr < end && *instr) + *ptr++ = *instr++; } - memcpy (pb->buf + pb->len, str, num); - pb->len += num; + pb->len = ptr - pb->buf; } void _stp_print_char (const char c) |