Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb2be58a

Browse files
authored
Merge pull request#1881 from romainmenke/improve-sourcemap-performance--philosophical-spiny-dogfish-3eb029c1c8
improve sourcemap performance
2 parents1c6ad25 +6a291d6 commitb2be58a

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

‎lib/map-generator.js‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class MapGenerator {
1717
this.opts=opts
1818
this.css=cssString
1919
this.usesFileUrls=!this.mapOpts.from&&this.mapOpts.absolute
20+
21+
this.memoizedFileURLs=newMap()
22+
this.memoizedPaths=newMap()
23+
this.memoizedURLs=newMap()
2024
}
2125

2226
addAnnotation(){
@@ -241,18 +245,22 @@ class MapGenerator {
241245
}
242246

243247
path(file){
244-
if(file.indexOf('<')===0)returnfile
245-
if(/^\w+:\/\//.test(file))returnfile
246248
if(this.mapOpts.absolute)returnfile
249+
if(file.charCodeAt(0)===60/* `<` */)returnfile
250+
if(/^\w+:\/\//.test(file))returnfile
251+
letcached=this.memoizedPaths.get(file)
252+
if(cached)returncached
247253

248254
letfrom=this.opts.to ?dirname(this.opts.to) :'.'
249255

250256
if(typeofthis.mapOpts.annotation==='string'){
251257
from=dirname(resolve(from,this.mapOpts.annotation))
252258
}
253259

254-
file=relative(from,file)
255-
returnfile
260+
letpath=relative(from,file)
261+
this.memoizedPaths.set(file,path)
262+
263+
returnpath
256264
}
257265

258266
previous(){
@@ -318,8 +326,14 @@ class MapGenerator {
318326
}
319327

320328
toFileUrl(path){
329+
letcached=this.memoizedFileURLs.get(path)
330+
if(cached)returncached
331+
321332
if(pathToFileURL){
322-
returnpathToFileURL(path).toString()
333+
letfileURL=pathToFileURL(path).toString()
334+
this.memoizedFileURLs.set(path,fileURL)
335+
336+
returnfileURL
323337
}else{
324338
thrownewError(
325339
'`map.absolute` option is not available in this PostCSS build'
@@ -328,10 +342,17 @@ class MapGenerator {
328342
}
329343

330344
toUrl(path){
345+
letcached=this.memoizedURLs.get(path)
346+
if(cached)returncached
347+
331348
if(sep==='\\'){
332349
path=path.replace(/\\/g,'/')
333350
}
334-
returnencodeURI(path).replace(/[#?]/g,encodeURIComponent)
351+
352+
leturl=encodeURI(path).replace(/[#?]/g,encodeURIComponent)
353+
this.memoizedURLs.set(path,url)
354+
355+
returnurl
335356
}
336357
}
337358

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp