File tree Expand file tree Collapse file tree 3 files changed +13
-4
lines changed
Expand file tree Collapse file tree 3 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 1+ import { LRUCache } from 'lru-cache' ;
12import PDFFont from '../font' ;
23
34const toHex = function ( num ) {
@@ -24,7 +25,9 @@ class EmbeddedFont extends PDFFont {
2425 this . bbox = this . font . bbox ;
2526
2627 if ( document . options . fontLayoutCache !== false ) {
27- this . layoutCache = Object . create ( null ) ;
28+ this . layoutCache = new LRUCache ( {
29+ max : document . options . fontLayoutMaxCacheSize || 1000
30+ } ) ;
2831 }
2932 }
3033
@@ -49,12 +52,12 @@ class EmbeddedFont extends PDFFont {
4952 return this . layoutRun ( text ) ;
5053 }
5154 let cached ;
52- if ( ( cached = this . layoutCache [ text ] ) ) {
55+ if ( ( cached = this . layoutCache . get ( text ) ) ) {
5356 return cached ;
5457 }
5558
5659 const run = this . layoutRun ( text ) ;
57- this . layoutCache [ text ] = run ;
60+ this . layoutCache . set ( text , run ) ;
5861 return run ;
5962 }
6063
Original file line number Diff line number Diff line change 5252 "fontkit" : " ^1.8.1" ,
5353 "jpeg-exif" : " ^1.1.4" ,
5454 "linebreak" : " ^1.0.2" ,
55+ "lru-cache" : " ^10.2.2" ,
5556 "png-js" : " ^1.0.0"
5657 },
5758 "scripts" : {
8990 " <rootDir>/tests/unit/setupTests.js"
9091 ]
9192 }
92- }
93+ }
Original file line number Diff line number Diff line change @@ -5016,6 +5016,11 @@ longest@^1.0.1:
50165016 resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
50175017 integrity sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=
50185018
5019+ lru-cache@^10.2.2 :
5020+ version "10.2.2"
5021+ resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.2.2.tgz#48206bc114c1252940c41b25b41af5b545aca878"
5022+ integrity sha512-9hp3Vp2/hFQUiIwKo8XCeFVnrg8Pk3TYNPIR7tJADKi5YfcF7vEaK7avFHTlSy3kOKYaJQaalfEo6YuXdceBOQ==
5023+
50195024lru-cache@^5.1.1 :
50205025 version "5.1.1"
50215026 resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920"
You can’t perform that action at this time.
0 commit comments