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

ruby-changes:15215

From: naruse <ko1@a...>
Date: Tue, 30 Mar 2010 03:58:58 +0900 (JST)
Subject: [ruby-changes:15215] Ruby:r27097 (trunk): * ext/psych/{emitter,parser,psych}.c: move variable

naruse	2010-03-30 03:58:22 +0900 (Tue, 30 Mar 2010)

  New Revision: 27097

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

  Log:
    * ext/psych/{emitter,parser,psych}.c: move variable
      declaration to the first of the block.

  Modified files:
    trunk/ChangeLog
    trunk/ext/psych/emitter.c
    trunk/ext/psych/parser.c
    trunk/ext/psych/psych.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 27096)
+++ ChangeLog	(revision 27097)
@@ -1,3 +1,8 @@
+Tue Mar 30 03:56:13 2010  NARUSE, Yui  <naruse@r...>
+
+	* ext/psych/{emitter,parser,psych}.c: move variable
+	  declaration to the first of the block.
+
 Mon Mar 29 21:47:44 2010  Akinori MUSHA  <knu@i...>
 
 	* prelude.rb, .document: Stuff in prelude.rb should be documented
Index: ext/psych/psych.c
===================================================================
--- ext/psych/psych.c	(revision 27096)
+++ ext/psych/psych.c	(revision 27097)
@@ -7,14 +7,13 @@
 static VALUE libyaml_version(VALUE module)
 {
     int major, minor, patch;
+    VALUE list[3];
 
     yaml_get_version(&major, &minor, &patch);
 
-    VALUE list[3] = {
-	INT2NUM((long)major),
-	INT2NUM((long)minor),
-	INT2NUM((long)patch)
-    };
+    list[0] = INT2NUM((long)major);
+    list[1] = INT2NUM((long)minor);
+    list[2] = INT2NUM((long)patch);
 
     return rb_ary_new4((long)3, list);
 }

Property changes on: ext/psych/psych.c
___________________________________________________________________
Name: svn:executable
   + *

Index: ext/psych/emitter.c
===================================================================
--- ext/psych/emitter.c	(revision 27096)
+++ ext/psych/emitter.c	(revision 27097)
@@ -56,10 +56,10 @@
 static VALUE start_stream(VALUE self, VALUE encoding)
 {
     yaml_emitter_t * emitter;
+    yaml_event_t event;
     Data_Get_Struct(self, yaml_emitter_t, emitter);
     Check_Type(encoding, T_FIXNUM);
 
-    yaml_event_t event;
     yaml_stream_start_event_initialize(&event, (yaml_encoding_t)NUM2INT(encoding));
 
     emit(emitter, &event);
@@ -76,9 +76,9 @@
 static VALUE end_stream(VALUE self)
 {
     yaml_emitter_t * emitter;
+    yaml_event_t event;
     Data_Get_Struct(self, yaml_emitter_t, emitter);
 
-    yaml_event_t event;
     yaml_stream_end_event_initialize(&event);
 
     emit(emitter, &event);
@@ -96,9 +96,12 @@
 static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp)
 {
     yaml_emitter_t * emitter;
+    yaml_tag_directive_t * head = NULL;
+    yaml_tag_directive_t * tail = NULL;
+    yaml_event_t event;
+    yaml_version_directive_t version_directive;
     Data_Get_Struct(self, yaml_emitter_t, emitter);
 
-    yaml_version_directive_t version_directive;
 
     Check_Type(version, T_ARRAY);
 
@@ -110,9 +113,6 @@
 	version_directive.minor = NUM2INT(minor);
     }
 
-    yaml_tag_directive_t * head = NULL;
-    yaml_tag_directive_t * tail = NULL;
-
     if(RTEST(tags)) {
 	int i = 0;
 
@@ -137,7 +137,6 @@
 	}
     }
 
-    yaml_event_t event;
     yaml_document_start_event_initialize(
 	    &event,
 	    (RARRAY_LEN(version) > 0) ? &version_directive : NULL,
@@ -162,9 +161,9 @@
 static VALUE end_document(VALUE self, VALUE imp)
 {
     yaml_emitter_t * emitter;
+    yaml_event_t event;
     Data_Get_Struct(self, yaml_emitter_t, emitter);
 
-    yaml_event_t event;
     yaml_document_end_event_initialize(&event, imp ? 1 : 0);
 
     emit(emitter, &event);
@@ -189,11 +188,11 @@
 	VALUE style
 	) {
     yaml_emitter_t * emitter;
+    yaml_event_t event;
     Data_Get_Struct(self, yaml_emitter_t, emitter);
 
     Check_Type(value, T_STRING);
 
-    yaml_event_t event;
     yaml_scalar_event_initialize(
 	    &event,
 	    (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValuePtr(anchor)),
@@ -225,9 +224,9 @@
 	VALUE style
 	) {
     yaml_emitter_t * emitter;
+    yaml_event_t event;
     Data_Get_Struct(self, yaml_emitter_t, emitter);
 
-    yaml_event_t event;
     yaml_sequence_start_event_initialize(
 	    &event,
 	    (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValuePtr(anchor)),
@@ -250,9 +249,9 @@
 static VALUE end_sequence(VALUE self)
 {
     yaml_emitter_t * emitter;
+    yaml_event_t event;
     Data_Get_Struct(self, yaml_emitter_t, emitter);
 
-    yaml_event_t event;
     yaml_sequence_end_event_initialize(&event);
 
     emit(emitter, &event);
@@ -275,9 +274,9 @@
 	VALUE style
 	) {
     yaml_emitter_t * emitter;
+    yaml_event_t event;
     Data_Get_Struct(self, yaml_emitter_t, emitter);
 
-    yaml_event_t event;
     yaml_mapping_start_event_initialize(
 	    &event,
 	    (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValuePtr(anchor)),
@@ -300,9 +299,9 @@
 static VALUE end_mapping(VALUE self)
 {
     yaml_emitter_t * emitter;
+    yaml_event_t event;
     Data_Get_Struct(self, yaml_emitter_t, emitter);
 
-    yaml_event_t event;
     yaml_mapping_end_event_initialize(&event);
 
     emit(emitter, &event);
@@ -319,9 +318,9 @@
 static VALUE alias(VALUE self, VALUE anchor)
 {
     yaml_emitter_t * emitter;
+    yaml_event_t event;
     Data_Get_Struct(self, yaml_emitter_t, emitter);
 
-    yaml_event_t event;
     yaml_alias_event_initialize(
 	    &event,
 	    (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValuePtr(anchor))

Property changes on: ext/psych/emitter.c
___________________________________________________________________
Name: svn:executable
   + *

Index: ext/psych/parser.c
===================================================================
--- ext/psych/parser.c	(revision 27096)
+++ ext/psych/parser.c	(revision 27097)
@@ -45,7 +45,13 @@
 {
     yaml_parser_t parser;
     yaml_event_t event;
+    int done = 0;
+#ifdef HAVE_RUBY_ENCODING_H
+    int encoding = rb_enc_find_index("ASCII-8BIT");
+#endif
+    VALUE handler = rb_iv_get(self, "@handler");
 
+
     yaml_parser_initialize(&parser);
 
     if(rb_respond_to(yaml, id_read)) {
@@ -58,13 +64,6 @@
 		);
     }
 
-    int done = 0;
-#ifdef HAVE_RUBY_ENCODING_H
-    int encoding = rb_enc_find_index("ASCII-8BIT");
-#endif
-
-    VALUE handler = rb_iv_get(self, "@handler");
-
     while(!done) {
 	if(!yaml_parser_parse(&parser, &event)) {
 	    size_t line   = parser.mark.line;
@@ -102,7 +101,9 @@
 		break;
 	    case YAML_DOCUMENT_START_EVENT:
 		{
-	// Grab the document version
+	/* Get a list of tag directives (if any) */
+	VALUE tag_directives = rb_ary_new();
+	/* Grab the document version */
 	VALUE version = event.data.document_start.version_directive ?
 	    rb_ary_new3(
 		    (long)2,
@@ -110,8 +111,6 @@
 		    INT2NUM((long)event.data.document_start.version_directive->minor)
 		 ) : rb_ary_new();
 
-	// Get a list of tag directives (if any)
-	VALUE tag_directives = rb_ary_new();
 	if(event.data.document_start.tag_directives.start) {
 	    yaml_tag_directive_t *start =
 		event.data.document_start.tag_directives.start;
@@ -119,6 +118,7 @@
 		event.data.document_start.tag_directives.end;
 	    for(; start != end; start++) {
 		VALUE handle = Qnil;
+		VALUE prefix = Qnil;
 		if(start->handle) {
 		    handle = rb_str_new2((const char *)start->handle);
 #ifdef HAVE_RUBY_ENCODING_H
@@ -126,7 +126,6 @@
 #endif
 		}
 
-		VALUE prefix = Qnil;
 		if(start->prefix) {
 		    prefix = rb_str_new2((const char *)start->prefix);
 #ifdef HAVE_RUBY_ENCODING_H
@@ -134,8 +133,7 @@
 #endif
 		}
 
-		VALUE pair = rb_ary_new3((long)2, handle, prefix);
-		rb_ary_push(tag_directives, pair);
+		rb_ary_push(tag_directives, rb_ary_new3((long)2, handle, prefix));
 	    }
 	}
 	rb_funcall(handler, id_start_document, 3,
@@ -164,6 +162,9 @@
 		break;
 	    case YAML_SCALAR_EVENT:
 		{
+	VALUE anchor = Qnil;
+	VALUE tag = Qnil;
+	VALUE plain_implicit, quoted_implicit, style;
 	VALUE val = rb_str_new(
 		(const char *)event.data.scalar.value,
 		(long)event.data.scalar.length
@@ -173,7 +174,6 @@
 	rb_enc_associate_index(val, encoding);
 #endif
 
-	VALUE anchor = Qnil;
 	if(event.data.scalar.anchor) {
 	    anchor = rb_str_new2((const char *)event.data.scalar.anchor);
 #ifdef HAVE_RUBY_ENCODING_H
@@ -181,7 +181,6 @@
 #endif
 	}
 
-	VALUE tag = Qnil;
 	if(event.data.scalar.tag) {
 	    tag = rb_str_new2((const char *)event.data.scalar.tag);
 #ifdef HAVE_RUBY_ENCODING_H
@@ -189,13 +188,13 @@
 #endif
 	}
 
-	VALUE plain_implicit =
+	plain_implicit =
 	    event.data.scalar.plain_implicit == 0 ? Qfalse : Qtrue;
 
-	VALUE quoted_implicit =
+	quoted_implicit =
 	    event.data.scalar.quoted_implicit == 0 ? Qfalse : Qtrue;
 
-	VALUE style = INT2NUM((long)event.data.scalar.style);
+	style = INT2NUM((long)event.data.scalar.style);
 
 	rb_funcall(handler, id_scalar, 6,
 		val, anchor, tag, plain_implicit, quoted_implicit, style);
@@ -204,6 +203,8 @@
 	    case YAML_SEQUENCE_START_EVENT:
 		{
 	VALUE anchor = Qnil;
+	VALUE tag = Qnil;
+	VALUE implicit, style;
 	if(event.data.sequence_start.anchor) {
 	    anchor = rb_str_new2((const char *)event.data.sequence_start.anchor);
 #ifdef HAVE_RUBY_ENCODING_H
@@ -211,7 +212,7 @@
 #endif
 	}
 
-	VALUE tag = Qnil;
+	tag = Qnil;
 	if(event.data.sequence_start.tag) {
 	    tag = rb_str_new2((const char *)event.data.sequence_start.tag);
 #ifdef HAVE_RUBY_ENCODING_H
@@ -219,10 +220,10 @@
 #endif
 	}
 
-	VALUE implicit =
+	implicit =
 	    event.data.sequence_start.implicit == 0 ? Qfalse : Qtrue;
 
-	VALUE style = INT2NUM((long)event.data.sequence_start.style);
+	style = INT2NUM((long)event.data.sequence_start.style);
 
 	rb_funcall(handler, id_start_sequence, 4,
 		anchor, tag, implicit, style);
@@ -234,6 +235,8 @@
 	    case YAML_MAPPING_START_EVENT:
 		{
 	VALUE anchor = Qnil;
+	VALUE tag = Qnil;
+	VALUE implicit, style;
 	if(event.data.mapping_start.anchor) {
 	    anchor = rb_str_new2((const char *)event.data.mapping_start.anchor);
 #ifdef HAVE_RUBY_ENCODING_H
@@ -241,7 +244,6 @@
 #endif
 	}
 
-	VALUE tag = Qnil;
 	if(event.data.mapping_start.tag) {
 	    tag = rb_str_new2((const char *)event.data.mapping_start.tag);
 #ifdef HAVE_RUBY_ENCODING_H
@@ -249,10 +251,10 @@
 #endif
 	}
 
-	VALUE implicit =
+	implicit =
 	    event.data.mapping_start.implicit == 0 ? Qfalse : Qtrue;
 
-	VALUE style = INT2NUM((long)event.data.mapping_start.style);
+	style = INT2NUM((long)event.data.mapping_start.style);
 
 	rb_funcall(handler, id_start_mapping, 4,
 		anchor, tag, implicit, style);

Property changes on: ext/psych/parser.c
___________________________________________________________________
Name: svn:executable
   + *


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

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