mirror of https://github.com/zlatinb/muwire
reduce Iterator churn and simplify HashBucket locking
parent
a1b25c3976
commit
4e0ab4d873
|
@ -46,7 +46,7 @@ class SearchTabController {
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<InfoHash> uniqueHashes = results.stream().map({it.infohash}).collect(Collectors.toSet())
|
Set<InfoHash> uniqueHashes = results.stream().map({it.infohash}).collect(Collectors.toSet())
|
||||||
results = uniqueHashes.stream().map({model.hashBucket[it].getResults().first()}).collect(Collectors.toList())
|
results = uniqueHashes.stream().map({model.hashBucket[it].firstEvent()}).collect(Collectors.toList())
|
||||||
|
|
||||||
File downloadsFolder = application.context.get("muwire-settings").downloadLocation
|
File downloadsFolder = application.context.get("muwire-settings").downloadLocation
|
||||||
List<ResultAndTargets> targets = view.decorateResults(results)
|
List<ResultAndTargets> targets = view.decorateResults(results)
|
||||||
|
|
|
@ -16,6 +16,7 @@ import griffon.metadata.ArtifactProviderFor
|
||||||
import javax.swing.SwingWorker
|
import javax.swing.SwingWorker
|
||||||
import javax.swing.tree.DefaultMutableTreeNode
|
import javax.swing.tree.DefaultMutableTreeNode
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
import java.util.concurrent.atomic.AtomicReference
|
||||||
|
|
||||||
@ArtifactProviderFor(GriffonModel)
|
@ArtifactProviderFor(GriffonModel)
|
||||||
class SearchTabModel {
|
class SearchTabModel {
|
||||||
|
@ -134,15 +135,20 @@ class SearchTabModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class HashBucket {
|
private static class HashBucket {
|
||||||
|
private final AtomicReference<UIResultEvent> first = new AtomicReference<>()
|
||||||
private final Set<UIResultEvent> events = new HashSet<>()
|
private final Set<UIResultEvent> events = new HashSet<>()
|
||||||
private final Set<Persona> senders = new HashSet<>()
|
private final Set<Persona> senders = new HashSet<>()
|
||||||
private String cachedName
|
|
||||||
private long cachedSize
|
|
||||||
private void add(UIResultEvent event) {
|
private void add(UIResultEvent event) {
|
||||||
|
first.compareAndSet(null, event)
|
||||||
events.add(event)
|
events.add(event)
|
||||||
senders.add(event.sender)
|
senders.add(event.sender)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UIResultEvent firstEvent() {
|
||||||
|
first.get()
|
||||||
|
}
|
||||||
|
|
||||||
Set<UIResultEvent> getResults() {
|
Set<UIResultEvent> getResults() {
|
||||||
events
|
events
|
||||||
}
|
}
|
||||||
|
@ -152,17 +158,11 @@ class SearchTabModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
String getName() {
|
String getName() {
|
||||||
if (cachedName == null) {
|
first.get().name
|
||||||
cachedName = events.first().name
|
|
||||||
}
|
|
||||||
cachedName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long getSize() {
|
long getSize() {
|
||||||
if (cachedSize == 0) {
|
first.get().size
|
||||||
cachedSize = events.first().size
|
|
||||||
}
|
|
||||||
cachedSize
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int sourceCount() {
|
int sourceCount() {
|
||||||
|
|
|
@ -163,7 +163,7 @@ class SearchTabView {
|
||||||
scrollPane(constraints : BorderLayout.CENTER) {
|
scrollPane(constraints : BorderLayout.CENTER) {
|
||||||
resultsTable2 = table(id : "results-table2", autoCreateRowSorter : true, rowHeight : rowHeight) {
|
resultsTable2 = table(id : "results-table2", autoCreateRowSorter : true, rowHeight : rowHeight) {
|
||||||
tableModel(list : model.results2) {
|
tableModel(list : model.results2) {
|
||||||
closureColumn(header : trans("NAME"), preferredWidth : 350, type : UIResultEvent, read : {model.hashBucket[it].getResults().first()})
|
closureColumn(header : trans("NAME"), preferredWidth : 350, type : UIResultEvent, read : {model.hashBucket[it].firstEvent()})
|
||||||
closureColumn(header : trans("SIZE"), preferredWidth : 20, type : Long, read : {
|
closureColumn(header : trans("SIZE"), preferredWidth : 20, type : Long, read : {
|
||||||
model.hashBucket[it].getSize()
|
model.hashBucket[it].getSize()
|
||||||
})
|
})
|
||||||
|
@ -605,7 +605,7 @@ class SearchTabView {
|
||||||
|
|
||||||
Persona sender = selectedSender()
|
Persona sender = selectedSender()
|
||||||
if (sender == null) // really shouldn't happen
|
if (sender == null) // really shouldn't happen
|
||||||
return model.hashBucket[infohash].getResults().first()
|
return model.hashBucket[infohash].firstEvent()
|
||||||
|
|
||||||
for (UIResultEvent candidate : model.hashBucket[infohash].getResults()) {
|
for (UIResultEvent candidate : model.hashBucket[infohash].getResults()) {
|
||||||
if (candidate.sender == sender)
|
if (candidate.sender == sender)
|
||||||
|
@ -613,7 +613,7 @@ class SearchTabView {
|
||||||
}
|
}
|
||||||
|
|
||||||
// also shouldn't happen
|
// also shouldn't happen
|
||||||
return model.hashBucket[infohash].getResults().first()
|
return model.hashBucket[infohash].firstEvent()
|
||||||
} else {
|
} else {
|
||||||
int[] selectedRows = resultsTable.getSelectedRows()
|
int[] selectedRows = resultsTable.getSelectedRows()
|
||||||
if (selectedRows.length != 1)
|
if (selectedRows.length != 1)
|
||||||
|
|
Loading…
Reference in New Issue