summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorMike Dalessio <mike.dalessio@gmail.com>2023-08-22 17:59:06 -0400
committergit <svn-admin@ruby-lang.org>2023-08-23 15:08:35 +0000
commitf902df128dea9044c226ed88306fca4d3a26f623 (patch)
tree8ce4060ffb134432f45c06245a5e5237c25ccc05 /test/ruby
parent58c1ebb634c8469026e1bdd0f7e65bfe72b9d9fc (diff)
[ruby/yarp] refactor: extract `peek_addr()`
In many places in the code we use the idiom: x < parser->end && *x == 'y' which is essentially an extension of an existing pattern: - `peek()` looks at `parser->current.end` - `peek_at()` looks at `(parser->current.end + offset)` This commit introduces a new inline function, `peek_addr`, which accepts a pointer and encapsulates the address value check and conditional dereferencing. The result is more readable code, and more ubiquitous safety checks on pointer values, allowing us to rewrite the above as: peek_addr(parser, x) == 'y' Also: - change the type of `peek_at()`'s offset argument from `size_t` to `ptrdiff_t` so that it can accept negative offsets. - use `current_token_starts_line` in one place where the equivalent code is inline. - use `peek` or `peek_at` to replace inline code in a few places These changes simplify the code and make it easier to visually spot patterns, particularly around line-endings (which will be a subject of a future pull request). https://github.com/ruby/yarp/commit/4c608d53ea
Diffstat (limited to 'test/ruby')
0 files changed, 0 insertions, 0 deletions