]> git.wincent.com - wikitext.git/commitdiff
Rename ary_delete_at to ary_pop
authorWincent Colaiuta <win@wincent.com>
Tue, 5 Feb 2008 06:23:12 +0000 (07:23 +0100)
committerWincent Colaiuta <win@wincent.com>
Tue, 5 Feb 2008 06:23:12 +0000 (07:23 +0100)
This better reflects what we actually expect the function to do and
guards against the possibility of asking it to do more than it can in
the future.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
ext/ary.h
ext/parser.c

index 98d36ef0c9d16eb010abbd0fb90f2d69db09482b..48bb6cc74abc656ab6695103e69e67a53ffb2c0f 100644 (file)
--- a/ext/ary.h
+++ b/ext/ary.h
@@ -48,9 +48,8 @@ inline int ary_entry(ary_t *ary, int idx)
     return (idx >= 0 && ary->count > idx) ? ary->entries[idx] : INT_MAX;
 }
 
-inline int ary_delete_at(ary_t *ary, int idx)
+inline int ary_pop(ary_t *ary)
 {
-    // dirty optimization: we know we'll only ever be called to delete the last element of the array
     if (ary->count > 0)
     {
         ary->count--;
index 5f3fbf2515fe0bcb46be7cc1e5d710bed52d8960..a9082f06010734813cf4d6b5754f6adcca8f6b32 100644 (file)
@@ -498,7 +498,7 @@ void _Wikitext_pop_from_stack(ary_t *stack, VALUE target, VALUE line_ending)
             // should probably raise an exception here
             break;
     }
-    ary_delete_at(stack, -1);
+    ary_pop(stack);
 }
 
 // Pops items off top of stack, accumulating closing tags for them into the target string, until item is reached.
@@ -1091,9 +1091,9 @@ VALUE Wikitext_parser_parse(VALUE self, VALUE string)
 
                 if (remove_strong > remove_em)      // must remove strong first
                 {
-                    ary_delete_at(scope, remove_strong);
+                    ary_pop(scope);
                     if (remove_em > -1)
-                        ary_delete_at(scope, remove_em);
+                        ary_pop(scope);
                     else    // there was no em to remove!, so consider this an opening em tag
                     {
                         rb_str_append(i, em_start());
@@ -1103,9 +1103,9 @@ VALUE Wikitext_parser_parse(VALUE self, VALUE string)
                 }
                 else if (remove_em > remove_strong) // must remove em first
                 {
-                    ary_delete_at(scope, remove_em);
+                    ary_pop(scope);
                     if (remove_strong > -1)
-                        ary_delete_at(scope, remove_strong);
+                        ary_pop(scope);
                     else    // there was no strong to remove!, so consider this an opening strong tag
                     {
                         rb_str_append(i, strong_start());
@@ -1929,7 +1929,7 @@ VALUE Wikitext_parser_parse(VALUE self, VALUE string)
                 if (ary_includes(scope, NO_WIKI_START))
                 {
                     // <nowiki> spans are unique; CRLFs are blindly echoed
-                    while (ary_delete_at(line_buffer, -1));
+                    while (ary_pop(line_buffer));
                     rb_str_append(output, line_ending);
                     pending_crlf = Qfalse;
                     break;
@@ -1976,8 +1976,8 @@ VALUE Wikitext_parser_parse(VALUE self, VALUE string)
                 }
 
                 // delete the entire contents of the line scope stack and buffer
-                while (ary_delete_at(line, -1));
-                while (ary_delete_at(line_buffer, -1));
+                while (ary_pop(line));
+                while (ary_pop(line_buffer));
                 break;
 
             case PRINTABLE: