From: hunt Date: Mon, 12 Nov 2007 21:57:31 +0000 (+0000) Subject: 2007-11-12 Martin Hunt X-Git-Tag: release-0.6~25 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=15e6cce92a4406ed68b4b0e57ec629ae4ddbd682;p=systemtap.git 2007-11-12 Martin Hunt * print.c (_stp_print): Rewrite to eliminate the strlen() call and save a bit of time. --- diff --git a/runtime/ChangeLog b/runtime/ChangeLog index e6079beab..24d584713 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,8 @@ +2007-11-12 Martin Hunt + + * print.c (_stp_print): Rewrite to eliminate the strlen() + call and save a bit of time. + 2007-11-09 Masami Hiramatsu PR3858 diff --git a/runtime/print.c b/runtime/print.c index 326d67d57..a451f6222 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)