summaryrefslogtreecommitdiffstats
path: root/dimension/lexer.l
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-05-08 23:21:48 -0600
committerTavian Barnes <tavianator@gmail.com>2010-05-08 23:21:48 -0600
commit7a21db5914dd7a5666e603d66ed3948b659ba2fc (patch)
treebde8e00a1677ba865adae8a82780d1cc832ece8e /dimension/lexer.l
parent152362a57dc7fe9dce830ef69118984f854d6375 (diff)
downloaddimension-7a21db5914dd7a5666e603d66ed3948b659ba2fc.tar.xz
New DMNSN_ARRAY_FOREACH() macro, faster than iterating with dmnsn_array_get().
Diffstat (limited to 'dimension/lexer.l')
-rw-r--r--dimension/lexer.l17
1 files changed, 6 insertions, 11 deletions
diff --git a/dimension/lexer.l b/dimension/lexer.l
index 6198fea..a3dc683 100644
--- a/dimension/lexer.l
+++ b/dimension/lexer.l
@@ -421,10 +421,8 @@ dmnsn_delete_token(dmnsn_token token)
void
dmnsn_delete_tokens(dmnsn_array *tokens)
{
- dmnsn_token token;
- for (size_t i = 0; i < dmnsn_array_size(tokens); ++i) {
- dmnsn_array_get(tokens, i, &token);
- dmnsn_delete_token(token);
+ DMNSN_ARRAY_FOREACH (dmnsn_token *, token, tokens) {
+ dmnsn_delete_token(*token);
}
dmnsn_delete_array(tokens);
}
@@ -453,19 +451,16 @@ dmnsn_print_token(FILE *file, dmnsn_token token)
void
dmnsn_print_token_sexpr(FILE *file, const dmnsn_array *tokens)
{
- dmnsn_token token;
-
if (dmnsn_array_size(tokens) == 0) {
fprintf(file, "()");
} else {
fprintf(file, "(");
- dmnsn_array_get(tokens, 0, &token);
- dmnsn_print_token(file, token);
+ dmnsn_token *token = dmnsn_array_first(tokens);
+ dmnsn_print_token(file, *token);
- for (size_t i = 1; i < dmnsn_array_size(tokens); ++i) {
+ for (++token; token <= (dmnsn_token *)dmnsn_array_last(tokens); ++token) {
fprintf(file, " ");
- dmnsn_array_get(tokens, i, &token);
- dmnsn_print_token(file, token);
+ dmnsn_print_token(file, *token);
}
fprintf(file, ")");