[前][次][番号順一覧][スレッド一覧]

ruby-changes:7002

From: nari <ko1@a...>
Date: Tue, 12 Aug 2008 16:02:19 +0900 (JST)
Subject: [ruby-changes:7002] Ruby:r18520 (trunk): * gc.c (gc_profile_result): use sprintf.

nari	2008-08-12 16:02:04 +0900 (Tue, 12 Aug 2008)

  New Revision: 18520

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18520

  Log:
    * gc.c (gc_profile_result): use sprintf.

  Modified files:
    trunk/ChangeLog
    trunk/gc.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 18519)
+++ ChangeLog	(revision 18520)
@@ -1,3 +1,7 @@
+Tue Aug 12 15:52:45 2008  Narihiro Nakamura  <authorNari@g...>
+
+	* gc.c (gc_profile_result): use sprintf.
+
 Tue Aug 12 15:37:40 2008  Yukihiro Matsumoto  <matz@r...>
 
 	* string.c (rb_str_intern): should check symbol table overflow.
Index: gc.c
===================================================================
--- gc.c	(revision 18519)
+++ gc.c	(revision 18520)
@@ -2709,40 +2709,43 @@
 {
     rb_objspace_t *objspace = &rb_objspace;
     VALUE record = gc_profile_record_get();
-    VALUE result;
+    VALUE result = rb_str_new2("");
     int i;
+    char buf[1024];
     
-    if (objspace->profile.run && objspace->profile.count) {
-	result = rb_sprintf("GC %1$d invokes.\n", NUM2INT(gc_count(0)));
+    if(objspace->profile.run && objspace->profile.count) {
+	sprintf(buf, "GC %d invokes.\n", NUM2INT(gc_count(0)));
+	rb_str_cat2(result, buf);
 	rb_str_cat2(result, "Index    Invoke Time(sec)       Use Size(byte)     Total Size(byte)         Total Object                    GC Time(ms)\n");
-	for (i = 0; i < (int)RARRAY_LEN(record); i++) {
+	for(i = 0; i < (int)RARRAY_LEN(record); i++) {
 	    VALUE r = RARRAY_PTR(record)[i];
-	    rb_str_catf(result, "%1$5d %2$19.3f %3$20d %4$20d %5$20d %6$30.20f\n",
-			i+1, NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_INVOKE_TIME")))),
-			NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_USE_SIZE")))),
-			NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_TOTAL_SIZE")))),
-			NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_TOTAL_OBJECTS")))),
-			NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_TIME"))))*100);
+	    memset(buf, 0, 1024);
+	    sprintf(buf, "%5d %19.3f %20d %20d %20d %30.20f\n",
+	    		i+1, NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_INVOKE_TIME")))),
+	    		NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_USE_SIZE")))),
+	    		NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_TOTAL_SIZE")))),
+	    		NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_TOTAL_OBJECTS")))),
+	    		NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_TIME"))))*100);
+	    rb_str_cat2(result, buf);
 	}
 #if GC_PROFILE_MORE_DETAIL
-	rb_str_concat(result, rb_str_new2("\n\n"));
-	rb_str_concat(result, rb_str_new2("More detail.\n"));
-	rb_str_concat(result, rb_str_new2("Index Allocate Increase    Allocate Limit  Use Slot  Have Finalize             Mark Time(ms)            Sweep Time(ms)\n"));
+	rb_str_cat2(result, "\n\n");
+	rb_str_cat2(result, "More detail.\n");
+	rb_str_cat2(result, "Index Allocate Increase    Allocate Limit  Use Slot  Have Finalize             Mark Time(ms)            Sweep Time(ms)\n");
 	for (i = 0; i < (int)RARRAY_LEN(record); i++) {
 	    VALUE r = RARRAY_PTR(record)[i];
-	    rb_str_catf(result, "%1$5d %2$17d %3$17d %4$9d %5$14s %6$25.20f %7$25.20f\n",
+	    memset(buf, 0, 1024);
+	    sprintf(buf, "%5d %17d %17d %9d %14s %25.20f %25.20f\n",
 			i+1, NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("ALLOCATE_INCREASE")))),
 			NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("ALLOCATE_LIMIT")))),
 			NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_USE_SLOTS")))),
 			rb_hash_aref(r, ID2SYM(rb_intern("HAVE_FINALIZE")))? "true" : "false",
 			NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_MARK_TIME"))))*100,
 			NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_SWEEP_TIME"))))*100);
+	    rb_str_cat2(result, buf);
 	}
 #endif
     }
-    else {
-	result = rb_str_new2("");
-    }
     return result;
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]