Skip to content

Commit c87f86e

Browse files
committed
Some simple, uncommentable Cursor tracking.
1 parent 62b8cab commit c87f86e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/NQP/Compiler.nqp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use QRegex;
2+
13
class NQP::Compiler is HLL::Compiler {
24
method optimize($past, *%adverbs) {
35
%adverbs<optimize> eq 'off'
@@ -43,6 +45,10 @@ sub MAIN(*@ARGS) {
4345
# Enter the compiler.
4446
$nqpcomp.command_line(@ARGS, :encoding('utf8'), :transcode('ascii iso-8859-1'));
4547

48+
# Uncomment below to dump cursor usage logging (also need to uncomment two lines
49+
# in src/QRegex/Cursor.nqp, in !cursor_start_cur and !cursor_start_all).
50+
#ParseShared.log_dump();
51+
4652
# Close event logging
4753
$nqpcomp.nqpevent();
4854
}

src/QRegex/Cursor.nqp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ my class ParseShared is export {
55
has int $!highwater;
66
has @!highexpect;
77
has %!marks;
8+
9+
# Follow is a little simple usage tracing infrastructure, used by the
10+
# !cursor_start_* methods when uncommented.
11+
my %cursors_created;
12+
my $cursors_total;
13+
method log_cc($name) {
14+
%cursors_created{$name}++;
15+
$cursors_total++;
16+
}
17+
method log_dump() {
18+
for %cursors_created {
19+
say($_.value ~ "\t" ~ $_.key);
20+
}
21+
say("TOTAL: " ~ $cursors_total);
22+
}
823
}
924

1025
role NQPCursorRole is export {
@@ -109,6 +124,8 @@ role NQPCursorRole is export {
109124
my @start_result;
110125
my $new := nqp::create(self);
111126
my $sub := nqp::callercode();
127+
# Uncomment following to log cursor creation.
128+
#$!shared.log_cc(nqp::getcodename($sub));
112129
nqp::bindattr($new, $?CLASS, '$!shared', $!shared);
113130
nqp::bindattr($new, $?CLASS, '$!regexsub', nqp::ifnull(nqp::getcodeobj($sub), $sub));
114131
if nqp::defined($!restart) {
@@ -138,6 +155,8 @@ role NQPCursorRole is export {
138155
method !cursor_start_cur() {
139156
my $new := nqp::create(self);
140157
my $sub := nqp::callercode();
158+
# Uncomment following to log cursor creation.
159+
#$!shared.log_cc(nqp::getcodename($sub));
141160
nqp::bindattr($new, $?CLASS, '$!shared', $!shared);
142161
nqp::bindattr($new, $?CLASS, '$!regexsub', nqp::ifnull(nqp::getcodeobj($sub), $sub));
143162
if nqp::defined($!restart) {

0 commit comments

Comments
 (0)