hhatto / gocloc

A little fast cloc(Count Lines Of Code)
MIT License
803 stars 81 forks source link

get rid of global file cache #7

Closed erizocosmico closed 6 years ago

erizocosmico commented 6 years ago

Hey there! I've been trying to use the library in parallel to process several thousands of repositories but I've run into concurrent map read and write panics doing so, this PR fixes it.

getAllFiles is only used once in Analyze (and thus the whole process), so the file cache should be created inside that function and passed to the md5 checker function rather than being global.

Another option is to guard the global file cache with a mutex, but that's not ideal, since the cache would grow more and more as you call Analyze.

hhatto commented 6 years ago

Thanks!! good catch 👍

fix unit test and merge to master.