ruby-changes:53755
From: duerst <ko1@a...>
Date: Sun, 25 Nov 2018 20:02:47 +0900 (JST)
Subject: [ruby-changes:53755] duerst:r65972 (trunk): create function create_property_node to extract recurring functionality
duerst 2018-11-25 20:02:41 +0900 (Sun, 25 Nov 2018) New Revision: 65972 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65972 Log: create function create_property_node to extract recurring functionality Refactoring: In regparse.c, extract creation of a new CClass node and initialization using a property into a new function create_property_node(). Modified files: trunk/regparse.c Index: regparse.c =================================================================== --- regparse.c (revision 65971) +++ regparse.c (revision 65972) @@ -5723,6 +5723,21 @@ extern const OnigCodePoint onigenc_unico https://github.com/ruby/ruby/blob/trunk/regparse.c#L5723 extern const OnigCodePoint onigenc_unicode_GCB_ranges_Emoji[]; static int +create_property_node(Node **np, ScanEnv* env, const char* propname) +{ + int r; + CClassNode* cc; + + *np = node_new_cclass(); + if (IS_NULL(*np)) return ONIGERR_MEMORY; + cc = NCCLASS(*np); + r = add_property_to_cc(cc, propname, 0, env); + if (r != 0) + onig_node_free(*np); + return r; +} + +static int node_extended_grapheme_cluster(Node** np, ScanEnv* env) { Node* tmp = NULL; @@ -5811,10 +5826,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5826 * | T+ */ /* T+ */ - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=T", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=T"); if (r != 0) goto err; tmp = node_new_quantifier(1, REPEAT_INFINITE, 0); @@ -5828,10 +5840,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5840 np1 = NULL; /* L+ */ - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=L", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=L"); if (r != 0) goto err; tmp = node_new_quantifier(1, REPEAT_INFINITE, 0); @@ -5845,10 +5854,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5854 np1 = NULL; /* L* LVT T* */ - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=T", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=T"); if (r != 0) goto err; tmp = node_new_quantifier(0, REPEAT_INFINITE, 0); @@ -5861,10 +5867,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5867 list2 = tmp; np1 = NULL; - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=LVT", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=LVT"); if (r != 0) goto err; tmp = node_new_list(np1, list2); @@ -5872,10 +5875,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5875 list2 = tmp; np1 = NULL; - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=L", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=L"); if (r != 0) goto err; tmp = node_new_quantifier(0, REPEAT_INFINITE, 0); @@ -5894,10 +5894,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5894 list2 = NULL; /* L* LV V* T* */ - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=T", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=T"); if (r != 0) goto err; tmp = node_new_quantifier(0, REPEAT_INFINITE, 0); @@ -5910,10 +5907,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5907 list2 = tmp; np1 = NULL; - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=V", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=V"); if (r != 0) goto err; tmp = node_new_quantifier(0, REPEAT_INFINITE, 0); @@ -5926,10 +5920,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5920 list2 = tmp; np1 = NULL; - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=LV", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=LV"); if (r != 0) goto err; tmp = node_new_list(np1, list2); @@ -5937,10 +5928,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5928 list2 = tmp; np1 = NULL; - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=L", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=L"); if (r != 0) goto err; tmp = node_new_quantifier(0, REPEAT_INFINITE, 0); @@ -5959,10 +5947,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5947 list2 = NULL; /* L* V+ T* */ - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=T", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=T"); if (r != 0) goto err; tmp = node_new_quantifier(0, REPEAT_INFINITE, 0); @@ -5975,10 +5960,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5960 list2 = tmp; np1 = NULL; - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=V", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=V"); if (r != 0) goto err; tmp = node_new_quantifier(1, REPEAT_INFINITE, 0); @@ -5991,10 +5973,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5973 list2 = tmp; np1 = NULL; - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=L", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=L"); if (r != 0) goto err; tmp = node_new_quantifier(0, REPEAT_INFINITE, 0); @@ -6016,10 +5995,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5995 * (ZWJ (Glue_After_Zwj | EBG Extend* E_Modifier?) )* */ /* ZWJ (Glue_After_Zwj | E_Base_GAZ Extend* E_Modifier?) */ - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=E_Modifier", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=E_Modifier"); if (r != 0) goto err; tmp = node_new_quantifier(0, 1, 0); @@ -6048,10 +6024,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L6024 list2 = tmp; np1 = NULL; - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=E_Base_GAZ", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=E_Base_GAZ"); if (r != 0) goto err; tmp = node_new_list(np1, list2); @@ -6167,10 +6140,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L6140 np1 = NULL; /* E_Modifier? */ - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=E_Modifier", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=E_Modifier"); if (r != 0) goto err; tmp = node_new_quantifier(0, 1, 0); @@ -6229,10 +6199,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L6199 * has such examples. * http://www.unicode.org/Public/9.0.0/ucd/auxiliary/GraphemeBreakTest.html */ - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=E_Modifier", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=E_Modifier"); if (r != 0) goto err; tmp = node_new_quantifier(0, 1, 0); @@ -6301,10 +6268,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L6268 alt = NULL; /* Prepend* */ - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=Prepend", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=Prepend"); if (r != 0) goto err; tmp = node_new_quantifier(0, REPEAT_INFINITE, 0); @@ -6349,10 +6313,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L6313 list2 = tmp; np1 = NULL; - np1 = node_new_cclass(); - if (IS_NULL(np1)) goto err; - cc = NCCLASS(np1); - r = add_property_to_cc(cc, "Grapheme_Cluster_Break=Prepend", 0, env); + r = create_property_node(&np1, env, "Grapheme_Cluster_Break=Prepend"); if (r != 0) goto err; tmp = node_new_quantifier(1, REPEAT_INFINITE, 0); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/