@@ -21,6 +21,7 @@ var modHalf = require('./mod').modHalf;
21
21
var isArrayOrTypedArray = require ( './array' ) . isArrayOrTypedArray ;
22
22
var isTypedArraySpec = require ( './array' ) . isTypedArraySpec ;
23
23
var decodeTypedArraySpec = require ( './array' ) . decodeTypedArraySpec ;
24
+ var coerceTypedArraySpec = require ( './array' ) . coerceTypedArraySpec ;
24
25
25
26
26
27
exports . valObjectMeta = {
@@ -42,7 +43,43 @@ exports.valObjectMeta = {
42
43
propOut . set ( v ) ;
43
44
wasSet = true ;
44
45
} else if ( isTypedArraySpec ( v ) ) {
45
- propOut . set ( decodeTypedArraySpec ( v ) ) ;
46
+ // Copy and coerce spec
47
+ v = coerceTypedArraySpec ( v ) ;
48
+
49
+ // See if caching location is available
50
+ var uid = propOut . obj . uid ;
51
+ var module = propOut . obj . _module ;
52
+
53
+ if ( v . bvals . constructor === ArrayBuffer || ! uid || ! module ) {
54
+ // Already an ArrayBuffer
55
+ // decoding is cheap
56
+ propOut . set ( decodeTypedArraySpec ( v ) ) ;
57
+ } else {
58
+ var prop = propOut . astr ;
59
+ var cache = module . _b64BufferCache || { } ;
60
+
61
+ // Check cache
62
+ var cachedBuffer = ( ( cache [ uid ] || { } ) [ prop ] || { } ) [ v . bvals ] ;
63
+ if ( cachedBuffer !== undefined ) {
64
+ // Use cached array buffer instead of base64 encoded
65
+ // string
66
+ v . bvals = cachedBuffer ;
67
+ propOut . set ( decodeTypedArraySpec ( v ) ) ;
68
+ } else {
69
+ // Not in so cache decode
70
+ var decoded = decodeTypedArraySpec ( v ) ;
71
+ propOut . set ( decoded ) ;
72
+
73
+ // Update cache for next time
74
+ cache [ uid ] = ( cache [ uid ] || { } ) ;
75
+
76
+ // Clear any prior cache value (only store one per
77
+ // trace property
78
+ cache [ uid ] [ prop ] = { } ;
79
+ cache [ uid ] [ prop ] [ v . bvals ] = decoded . buffer ;
80
+ module . _b64BufferCache = cache ;
81
+ }
82
+ }
46
83
wasSet = true ;
47
84
}
48
85
if ( ! wasSet && dflt !== undefined ) propOut . set ( dflt ) ;
0 commit comments