]> sourceware.org Git - systemtap.git/commitdiff
2007-11-12 Martin Hunt <hunt@redhat.com>
authorhunt <hunt>
Mon, 12 Nov 2007 21:57:31 +0000 (21:57 +0000)
committerhunt <hunt>
Mon, 12 Nov 2007 21:57:31 +0000 (21:57 +0000)
* print.c (_stp_print): Rewrite to eliminate the strlen()
call and save a bit of time.

runtime/ChangeLog
runtime/print.c

index e6079beab792dbbc684ac33e69212aa1d81397ab..24d584713c282c8c78dadcae4fee0ce4b2289d4e 100644 (file)
@@ -1,3 +1,8 @@
+2007-11-12  Martin Hunt  <hunt@redhat.com>
+
+       * print.c (_stp_print): Rewrite to eliminate the strlen()
+       call and save a bit of time.
+
 2007-11-09  Masami Hiramatsu  <mhiramat@redhat.com>
 
        PR3858
index 326d67d576ed752d26c8eef08fdbda7460feb653..a451f62227a33fdeb7fd0009a45aeba33407fea6 100644 (file)
@@ -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)
This page took 0.034885 seconds and 5 git commands to generate.