Skip to content

Commit 54d7e21

Browse files
committed
[js] Tweak multi caches to cache rw containers separately
1 parent 9c4bd91 commit 54d7e21

File tree

7 files changed

+46
-11
lines changed

7 files changed

+46
-11
lines changed

src/vm/js/nqp-runtime/multicache.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,28 @@ function posTypes(ctx, capture) {
1919
var obj = capture.pos[i];
2020
if (obj._STable) {
2121
let deconted = obj.$$decont(ctx);
22-
types[i] = deconted.typeObject_ ? deconted : deconted._STable;
22+
if (!obj.$$isrwcont) {
23+
console.log("attempting to cache");
24+
require('nqp-runtime').dumpObj(obj);
25+
}
26+
27+
/* TODO - think if having flags wouldn't be faster/cleaner then weird objects */
28+
if (obj.$$isrwcont()) {
29+
if (deconted.typeObject_) {
30+
if (deconted._STable.typeObjectCachedAsRW === undefined) {
31+
deconted._STable.typeObjectCachedAsRW = {};
32+
}
33+
types[i] = deconted._STable.typeObjectCachedAsRW;
34+
} else {
35+
if (deconted._STable.cachedAsRW === undefined) {
36+
deconted._STable.cachedAsRW = {};
37+
}
38+
types[i] = deconted._STable.cachedAsRW;
39+
}
40+
41+
} else {
42+
types[i] = deconted.typeObject_ ? deconted : deconted._STable;
43+
}
2344
} else if (obj instanceof NQPInt) {
2445
types[i] = 1;
2546
} else if (typeof obj == 'number') {

src/vm/js/nqp-runtime/nqp-exception.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class NQPException extends Error {
1919
$$istype(ctx, type) {
2020
return 0;
2121
}
22+
23+
$$isrwcont() {
24+
return 0;
25+
}
2226
};
2327

2428
NQPException.prototype._STable = {

src/vm/js/nqp-runtime/nqp-object.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ class NQPObject {
44
$$decont(ctx) {
55
return this;
66
}
7+
8+
$$isrwcont() {
9+
return 0;
10+
}
711
};
812

913
module.exports = NQPObject;

src/vm/js/nqp-runtime/null.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
'use strict';
2+
let NQPObject = require('./nqp-object.js');
23
let singleton;
3-
class Null {
4-
$$decont(ctx) {
5-
return this;
6-
}
7-
4+
class Null extends NQPObject {
85
$$toBool(ctx) {
96
return 0;
107
}

src/vm/js/nqp-runtime/null_s.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
'use strict';
2-
class NullS {
2+
let NQPObject = require('./nqp-object.js');
3+
class NullS extends NQPObject {
34
toString() {
45
console.trace('here');
56
throw 'doing string stuff on a null_s';
67
}
78

8-
$$decont(ctx) {
9-
return this;
10-
}
11-
129
$$istype(ctx, type) {
1310
return 0;
1411
}

src/vm/js/nqp-runtime/runtime.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ Number.prototype.$$can = function(ctx, name) {
396396
return 0;
397397
};
398398

399+
Number.prototype.$$isrwcont = function(ctx) {
400+
return 0;
401+
};
402+
399403
String.prototype.$$decont = function(ctx) {
400404
return this;
401405
};
@@ -412,6 +416,10 @@ String.prototype.$$istype = function(ctx, type) {
412416
return 0;
413417
};
414418

419+
String.prototype.$$isrwcont = function(ctx) {
420+
return 0;
421+
};
422+
415423
// needed for continuations
416424
Function.prototype.$$toBool = function(ctx) {
417425
return 1;

src/vm/js/nqp-runtime/sixmodel.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class STable {
6363
return this;
6464
};
6565

66+
this.objConstructor.prototype.$$isrwcont = function() {
67+
return 0;
68+
};
69+
6670
this.objConstructor.prototype.typeObject_ = 0;
6771

6872
this.objConstructor.prototype.$$call = undefined;

0 commit comments

Comments
 (0)