Revision: 1116
Author: [email protected]
Date: Mon Mar  8 01:47:43 2010
Log: Move output_tag_int(), output_nv() and output_str() to FileHandle.xs from
NYTProf.xs, and make them static. Remove their prototypes from NYTProf.h.
http://code.google.com/p/perl-devel-nytprof/source/detail?r=1116

Modified:
 /trunk/FileHandle.h
 /trunk/FileHandle.xs
 /trunk/NYTProf.h
 /trunk/NYTProf.xs

=======================================
--- /trunk/FileHandle.h Mon Mar  8 01:47:36 2010
+++ /trunk/FileHandle.h Mon Mar  8 01:47:43 2010
@@ -43,6 +43,7 @@
 #  define NYTP_type_of_offset(file) ""
 #endif

+#define NYTP_TAG_NO_TAG '\0' /* Used as a flag to mean "no tag" */
 #define NYTP_TAG_ATTRIBUTE       ':'    /* :name=value\n */
 #define NYTP_TAG_COMMENT         '#'    /* till newline */
 #define NYTP_TAG_TIME_BLOCK      '*'
=======================================
--- /trunk/FileHandle.xs        Mon Mar  8 01:47:36 2010
+++ /trunk/FileHandle.xs        Mon Mar  8 01:47:43 2010
@@ -621,6 +621,87 @@
     }
     return fclose(raw_file) == 0 ? 0 : errno;
 }
+
+/**
+ * Output an integer in bytes, optionally preceded by a tag. Use the special tag + * NYTP_TAG_NO_TAG to suppress the tag output. A wrapper macro output_int(fh, i)
+ * does this for you.
+ * "In bytes" means output the number in binary, using the least number of bytes
+ * possible.  All numbers are positive. Use sign slot as a marker
+ */
+static size_t
+output_tag_int(NYTP_file file, unsigned char tag, unsigned int i)
+{
+    U8 buffer[6];
+    U8 *p = buffer;
+
+    if (tag != NYTP_TAG_NO_TAG)
+        *p++ = tag;
+
+    /* general case. handles all integers */
+    if (i < 0x80) {                               /* < 8 bits */
+        *p++ = (U8)i;
+    }
+    else if (i < 0x4000) {                        /* < 15 bits */
+        *p++ = (U8)((i >> 8) | 0x80);
+        *p++ = (U8)i;
+    }
+    else if (i < 0x200000) {                      /* < 22 bits */
+        *p++ = (U8)((i >> 16) | 0xC0);
+        *p++ = (U8)(i >> 8);
+        *p++ = (U8)i;
+    }
+    else if (i < 0x10000000) {                    /* 32 bits */
+        *p++ = (U8)((i >> 24) | 0xE0);
+        *p++ = (U8)(i >> 16);
+        *p++ = (U8)(i >> 8);
+        *p++ = (U8)i;
+    }
+    else {                                        /* need all the bytes. */
+        *p++ = 0xFF;
+        *p++ = (U8)(i >> 24);
+        *p++ = (U8)(i >> 16);
+        *p++ = (U8)(i >> 8);
+        *p++ = (U8)i;
+    }
+    return NYTP_write(file, buffer, p - buffer);
+}
+
+#define output_int(fh, i) output_tag_int((fh), NYTP_TAG_NO_TAG, (unsigned int)(i))
+
+static size_t
+output_str(NYTP_file file, const char *str, I32 len) { /* negative len signifies utf8 */
+    unsigned char tag = NYTP_TAG_STRING;
+    size_t retval;
+    size_t total;
+
+    if (len < 0) {
+        tag = NYTP_TAG_STRING_UTF8;
+        len = -len;
+    }
+
+    total = retval = output_tag_int(file, tag, len);
+    if (retval <= 0)
+        return retval;
+
+    if (len) {
+        total += retval = NYTP_write(file, str, len);
+        if (retval <= 0)
+            return retval;
+    }
+
+    return total;
+}
+
+/**
+ * Output a double precision float via a simple binary write of the memory.
+ * (Minor portbility issues are seen as less important than speed and space.)
+ */
+size_t
+output_nv(NYTP_file file, NV nv)
+{
+    return NYTP_write(file, (unsigned char *)&nv, sizeof(NV));
+}

 size_t
 NYTP_write_comment(NYTP_file ofile, const char *format, ...) {
=======================================
--- /trunk/NYTProf.h    Mon Mar  8 01:46:08 2010
+++ /trunk/NYTProf.h    Mon Mar  8 01:47:43 2010
@@ -16,13 +16,3 @@
  * ************************************************************************
  */

-/* FIXME - The callers of these functions should be refactored into their own - library file, with a public API, the XS interface adapted to use that API,
-   and these 3 return to being static functions, within that library.  */
-
-size_t output_tag_int(NYTP_file file, unsigned char tag, unsigned int);
-size_t output_str(NYTP_file file, const char *str, I32 len);
-size_t output_nv(NYTP_file file, NV nv);
-
-#define NYTP_TAG_NO_TAG '\0' /* Used as a flag to mean "no tag" */ -#define output_int(fh, i) output_tag_int((fh), NYTP_TAG_NO_TAG, (unsigned int)(i))
=======================================
--- /trunk/NYTProf.xs   Mon Mar  8 01:47:36 2010
+++ /trunk/NYTProf.xs   Mon Mar  8 01:47:43 2010
@@ -466,34 +466,6 @@

     NYTP_flush(out);
 }
-
-
-size_t
-output_str(NYTP_file file, const char *str, I32 len) { /* negative len signifies utf8 */
-    unsigned char tag = NYTP_TAG_STRING;
-    size_t retval;
-    size_t total;
-
-    if (len < 0) {
-        tag = NYTP_TAG_STRING_UTF8;
-        len = -len;
-    }
-    if (trace_level >= 10)
-        logwarn("output_str('%.*s', %d)\n", (int)len, str, (int)len);
-
-    total = retval = output_tag_int(file, tag, len);
-    if (retval <= 0)
-        return retval;
-
-    if (len) {
-        total += retval = NYTP_write(file, str, len);
-        if (retval <= 0)
-            return retval;
-    }
-
-    return total;
-}
-

 static SV *
 read_str(pTHX_ NYTP_file ifile, SV *sv) {
@@ -968,53 +940,6 @@

     return found->id;
 }
-
-
-/**
- * Output an integer in bytes, optionally preceded by a tag. Use the special tag - * NYTP_TAG_NO_TAG to suppress the tag output. A wrapper macro output_int(fh, i)
- * does this for you.
- * "In bytes" means output the number in binary, using the least number of bytes
- * possible.  All numbers are positive. Use sign slot as a marker
- */
-size_t
-output_tag_int(NYTP_file file, unsigned char tag, unsigned int i)
-{
-    U8 buffer[6];
-    U8 *p = buffer;
-
-    if (tag != NYTP_TAG_NO_TAG)
-        *p++ = tag;
-
-    /* general case. handles all integers */
-    if (i < 0x80) {                               /* < 8 bits */
-        *p++ = (U8)i;
-    }
-    else if (i < 0x4000) {                        /* < 15 bits */
-        *p++ = (U8)((i >> 8) | 0x80);
-        *p++ = (U8)i;
-    }
-    else if (i < 0x200000) {                      /* < 22 bits */
-        *p++ = (U8)((i >> 16) | 0xC0);
-        *p++ = (U8)(i >> 8);
-        *p++ = (U8)i;
-    }
-    else if (i < 0x10000000) {                    /* 32 bits */
-        *p++ = (U8)((i >> 24) | 0xE0);
-        *p++ = (U8)(i >> 16);
-        *p++ = (U8)(i >> 8);
-        *p++ = (U8)i;
-    }
-    else {                                        /* need all the bytes. */
-        *p++ = 0xFF;
-        *p++ = (U8)(i >> 24);
-        *p++ = (U8)(i >> 16);
-        *p++ = (U8)(i >> 8);
-        *p++ = (U8)i;
-    }
-    return NYTP_write(file, buffer, p - buffer);
-}
-

 static UV
 uv_from_av(pTHX_ AV *av, int idx, UV default_uv)
@@ -1023,19 +948,6 @@
     UV uv = (!svp || !SvOK(*svp)) ? default_uv : SvUV(*svp);
     return uv;
 }
-
-
-
-/**
- * Output a double precision float via a simple binary write of the memory.
- * (Minor portbility issues are seen as less important than speed and space.)
- */
-size_t
-output_nv(NYTP_file file, NV nv)
-{
-    return NYTP_write(file, (unsigned char *)&nv, sizeof(NV));
-}
-

 static NV
 nv_from_av(pTHX_ AV *av, int idx, NV default_nv)

--
You've received this message because you are subscribed to
the Devel::NYTProf Development User group.

Group hosted at:  http://groups.google.com/group/develnytprof-dev
Project hosted at:  http://perl-devel-nytprof.googlecode.com
CPAN distribution:  http://search.cpan.org/dist/Devel-NYTProf

To post, email:  [email protected]
To unsubscribe, email:  [email protected]

Reply via email to