summaryrefslogtreecommitdiff
path: root/ext/syck
diff options
context:
space:
mode:
authorwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-03 19:51:25 +0000
committerwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-03 19:51:25 +0000
commitdf0e9dbe9772d7327481ec95ad4dd33a12c1d470 (patch)
tree5128b896e4471a8f1aff392261658c487ea4ff61 /ext/syck
parent7d18f560f5b25bee62c26a80ccc97f7de618fc8f (diff)
* ext/syck/rubyext.c: default keys handled.
* ext/syck/syck.h: lowered default buffer size to 16k for increased performance. * test/yaml: checkin of basic unit tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/syck')
-rw-r--r--ext/syck/rubyext.c33
-rw-r--r--ext/syck/syck.h2
2 files changed, 25 insertions, 10 deletions
diff --git a/ext/syck/rubyext.c b/ext/syck/rubyext.c
index 5b35047..e7ec534 100644
--- a/ext/syck/rubyext.c
+++ b/ext/syck/rubyext.c
@@ -40,10 +40,10 @@ typedef struct RVALUE {
/*
* symbols and constants
*/
-static ID s_new, s_utc, s_at, s_to_f, s_read, s_binmode, s_call, s_transfer, s_update, s_dup, s_match, s_keys, s_to_str, s_unpack, s_tr_bang;
+static ID s_new, s_utc, s_at, s_to_f, s_read, s_binmode, s_call, s_transfer, s_update, s_dup, s_match, s_keys, s_to_str, s_unpack, s_tr_bang, s_anchors, s_default_set;
static VALUE sym_model, sym_generic;
static VALUE sym_scalar, sym_seq, sym_map;
-VALUE cDate, cParser, cLoader, cNode, cPrivateType, cDomainType, cBadAlias, cMergeKey, cEmitter;
+VALUE cDate, cParser, cLoader, cNode, cPrivateType, cDomainType, cBadAlias, cDefaultKey, cMergeKey, cEmitter;
VALUE oDefaultLoader;
/*
@@ -364,9 +364,6 @@ yaml_org_handler( n, ref )
long i = 0;
VALUE obj = Qnil;
- /*
- * If prefixed with YAML_DOMAIN, skip to type name
- */
switch (n->kind)
{
case syck_str_kind:
@@ -464,6 +461,10 @@ yaml_org_handler( n, ref )
{
obj = rb_funcall( cMergeKey, s_new, 0 );
}
+ else if ( strncmp( type_id, "default", 7 ) == 0 )
+ {
+ obj = rb_funcall( cDefaultKey, s_new, 0 );
+ }
else
{
transferred = 0;
@@ -489,7 +490,7 @@ yaml_org_handler( n, ref )
{
VALUE k = syck_map_read( n, map_key, i );
VALUE v = syck_map_read( n, map_value, i );
- int merge_key = 0;
+ int skip_aset = 0;
/*
* Handle merge keys
@@ -501,7 +502,7 @@ yaml_org_handler( n, ref )
VALUE dup = rb_funcall( v, s_dup, 0 );
rb_funcall( dup, s_update, 1, obj );
obj = dup;
- merge_key = 1;
+ skip_aset = 1;
}
else if ( rb_obj_is_kind_of( v, rb_cArray ) )
{
@@ -513,12 +514,17 @@ yaml_org_handler( n, ref )
rb_ary_push( v, obj );
rb_iterate( rb_each, v, syck_merge_i, dup );
obj = dup;
- merge_key = 1;
+ skip_aset = 1;
}
}
}
+ else if ( rb_obj_is_kind_of( k, cDefaultKey ) )
+ {
+ rb_funcall( obj, s_default_set, 1, v );
+ skip_aset = 1;
+ }
- if ( ! merge_key )
+ if ( ! skip_aset )
{
rb_hash_aset( obj, k, v );
}
@@ -762,6 +768,7 @@ syck_loader_initialize( self )
rb_iv_set(self, "@families", rb_hash_new() );
rb_iv_set(self, "@private_types", rb_hash_new() );
+ rb_iv_set(self, "@anchors", rb_hash_new() );
families = rb_iv_get(self, "@families");
rb_hash_aset(families, rb_str_new2( YAML_DOMAIN ), rb_hash_new());
@@ -1274,11 +1281,13 @@ Init_syck()
s_at = rb_intern("at");
s_to_f = rb_intern("to_f");
s_read = rb_intern("read");
+ s_anchors = rb_intern("anchors");
s_binmode = rb_intern("binmode");
s_transfer = rb_intern("transfer");
s_call = rb_intern("call");
s_update = rb_intern("update");
s_dup = rb_intern("dup");
+ s_default_set = rb_intern("default=");
s_match = rb_intern("match");
s_keys = rb_intern("keys");
s_to_str = rb_intern("to_str");
@@ -1303,6 +1312,7 @@ Init_syck()
cLoader = rb_define_class_under( rb_syck, "Loader", rb_cObject );
rb_define_attr( cLoader, "families", 1, 1 );
rb_define_attr( cLoader, "private_types", 1, 1 );
+ rb_define_attr( cLoader, "anchors", 1, 1 );
rb_define_method( cLoader, "initialize", syck_loader_initialize, 0 );
rb_define_method( cLoader, "add_domain_type", syck_loader_add_domain_type, -1 );
rb_define_method( cLoader, "add_builtin_type", syck_loader_add_builtin_type, -1 );
@@ -1364,6 +1374,11 @@ Init_syck()
*/
cMergeKey = rb_define_class_under( rb_syck, "MergeKey", rb_cObject );
+ /*
+ * Define YAML::Syck::DefaultKey class
+ */
+ cDefaultKey = rb_define_class_under( rb_syck, "DefaultKey", rb_cObject );
+
/*
* Define YAML::Syck::Emitter class
*/
diff --git a/ext/syck/syck.h b/ext/syck/syck.h
index 49efd35..8c10f0d 100644
--- a/ext/syck/syck.h
+++ b/ext/syck/syck.h
@@ -47,7 +47,7 @@ extern "C" {
#endif
#define ALLOC_CT 8
-#define SYCK_BUFFERSIZE 262144
+#define SYCK_BUFFERSIZE 16384
#define S_ALLOC_N(type,n) (type*)malloc(sizeof(type)*(n))
#define S_ALLOC(type) (type*)malloc(sizeof(type))
#define S_REALLOC_N(var,type,n) (var)=(type*)realloc((char*)(var),sizeof(type)*(n))