avoid storing values in memory when IndexGenerator.CHECK_HASH_COLLISIONS is on

This commit is contained in:
Artem Khvastunov
2018-07-06 18:15:32 +02:00
parent b84b90637d
commit ddd28d2cfd

View File

@@ -38,7 +38,7 @@ abstract class IndexGenerator<Value>(private val indexStorageFilePath: String) {
println("Writing indices to ${storage.baseFile.absolutePath}")
storage.use {
val map = HashMap<HashCode, Pair<String, Value>>()
val map = HashMap<HashCode, String>()
for (file in roots) {
println("Processing files in root ${file.path}")
@@ -57,7 +57,7 @@ abstract class IndexGenerator<Value>(private val indexStorageFilePath: String) {
private fun indexFile(file: VirtualFile,
hashing: FileContentHashing,
map: HashMap<HashCode, Pair<String, Value>>,
map: MutableMap<HashCode, String>,
storage: PersistentHashMap<HashCode, Value>,
stats: Stats): Boolean {
try {
@@ -77,13 +77,12 @@ abstract class IndexGenerator<Value>(private val indexStorageFilePath: String) {
stats.indexed.incrementAndGet()
if (CHECK_HASH_COLLISIONS) {
map[hashCode] = Pair(fileContent.contentAsText.toString(), value)
map[hashCode] = fileContent.contentAsText.toString()
}
}
else {
TestCase.assertEquals(item.first,
fileContent.contentAsText.toString())
TestCase.assertTrue(value == item.second)
TestCase.assertEquals(item, fileContent.contentAsText.toString())
TestCase.assertTrue(storage.get(hashCode) == value)
}
}
else {