@@ -21,6 +21,7 @@ var modHalf = require('./mod').modHalf;
2121var isArrayOrTypedArray = require ( './array' ) . isArrayOrTypedArray ;
2222var isTypedArraySpec = require ( './array' ) . isTypedArraySpec ;
2323var decodeTypedArraySpec = require ( './array' ) . decodeTypedArraySpec ;
24+ var coerceTypedArraySpec = require ( './array' ) . coerceTypedArraySpec ;
2425
2526
2627exports . valObjectMeta = {
@@ -42,7 +43,43 @@ exports.valObjectMeta = {
4243 propOut . set ( v ) ;
4344 wasSet = true ;
4445 } 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+ }
4683 wasSet = true ;
4784 }
4885 if ( ! wasSet && dflt !== undefined ) propOut . set ( dflt ) ;
0 commit comments