File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,9 @@ knowhow NQPClassHOW {
30
30
31
31
# Full list of roles that we do.
32
32
has @ ! done ;
33
+
34
+ # Cached values, which are thrown away if the class changes.
35
+ has % ! cache ;
33
36
34
37
# Parrot-specific vtable mapping hash. Maps vtable name to method.
35
38
has % ! parrot_vtable_mapping ;
@@ -72,6 +75,7 @@ knowhow NQPClassHOW {
72
75
pir::die(" Cannot add a null method '$ name ' to class '$ ! name '" );
73
76
}
74
77
pir::set_method_cache_authoritativeness__vPi($ obj , 0 );
78
+ % ! cache := {};
75
79
% ! methods {$ name } := $ code_obj ;
76
80
}
77
81
@@ -393,6 +397,7 @@ knowhow NQPClassHOW {
393
397
pir::stable_publish_vtable_handler_mapping__vPP($ obj , % mapping );
394
398
}
395
399
}
400
+
396
401
# #
397
402
# # Introspecty
398
403
# #
@@ -492,4 +497,14 @@ knowhow NQPClassHOW {
492
497
}
493
498
pir::null__P()
494
499
}
500
+
501
+ # #
502
+ # # Cache-related
503
+ # #
504
+ method cache ($ obj , $ key , $ value_generator ) {
505
+ % ! cache || (% ! cache := {});
506
+ pir:: exists (% ! cache , $ key ) ??
507
+ % ! cache {$ key } !!
508
+ (% ! cache {$ key } := $ value_generator ())
509
+ }
495
510
}
You can’t perform that action at this time.
0 commit comments