Merge remote-tracking branch 'origin/GT-2862-dragonmacher-byte-viewer-cursor'

This commit is contained in:
Ryan Kurtz 2019-05-15 13:14:34 -04:00
commit 45cf2564a6
2 changed files with 40 additions and 16 deletions

View file

@ -53,9 +53,7 @@ public class ListingModelAdapter implements LayoutModel, ListingModelListener {
removeUnviewableAddressRanges(); removeUnviewableAddressRanges();
model.addListener(this); model.addListener(this);
updateMgr = new SwingUpdateManager(500, 5000, new Runnable() { updateMgr = new SwingUpdateManager(500, 5000, () -> {
@Override
public void run() {
if (!model.isClosed()) { if (!model.isClosed()) {
resetIndexMap(); resetIndexMap();
for (LayoutModelListener listener : listeners) { for (LayoutModelListener listener : listeners) {
@ -63,7 +61,6 @@ public class ListingModelAdapter implements LayoutModel, ListingModelListener {
} }
preferredViewSize = null; preferredViewSize = null;
} }
}
}); });
} }
@ -217,7 +214,6 @@ public class ListingModelAdapter implements LayoutModel, ListingModelListener {
if (floc != null) { if (floc != null) {
return floc; return floc;
} }
return getFieldLocation(location.getAddress(), location, true); return getFieldLocation(location.getAddress(), location, true);
} }
@ -237,7 +233,7 @@ public class ListingModelAdapter implements LayoutModel, ListingModelListener {
BigInteger index = addressToIndexMap.getIndex(address); BigInteger index = addressToIndexMap.getIndex(address);
Layout layout = getLayout(index); Layout layout = getLayout(index);
if (layout == null) { if (layout == null) {
index = getLayoutForArrayElement(address); index = getLayoutWithinCodeUnit(address);
layout = getLayout(index); layout = getLayout(index);
} }
@ -272,11 +268,12 @@ public class ListingModelAdapter implements LayoutModel, ListingModelListener {
return null; return null;
} }
private BigInteger getLayoutForArrayElement(Address address) { private BigInteger getLayoutWithinCodeUnit(Address address) {
CodeUnit cu = model.getProgram().getListing().getCodeUnitContaining(address); CodeUnit cu = model.getProgram().getListing().getCodeUnitContaining(address);
if (cu == null) { if (cu == null) {
return null; return null;
} }
Address min = cu.getMinAddress(); Address min = cu.getMinAddress();
while (address.compareTo(min) > 0) { while (address.compareTo(min) > 0) {
address = address.subtract(1); address = address.subtract(1);

View file

@ -53,7 +53,7 @@ public class ProgramBigListingModel implements ListingModel, FormatModelListener
private List<ListingModelListener> listeners = new ArrayList<>(); private List<ListingModelListener> listeners = new ArrayList<>();
// Use a cache so that simple arrowing to-and-fro with the keyboard will respond quickly // Use a cache so that simple arrowing to-and-fro with the keyboard will respond quickly
private LRUMap<Address, Layout> layoutCache = new LRUMap<>(10); private LayoutCache layoutCache = new LayoutCache();
public ProgramBigListingModel(Program program, FormatManager formatMgr) { public ProgramBigListingModel(Program program, FormatManager formatMgr) {
this.program = program; this.program = program;
@ -124,15 +124,15 @@ public class ProgramBigListingModel implements ListingModel, FormatModelListener
@Override @Override
public Layout getLayout(Address addr, boolean isGapAddress) { public Layout getLayout(Address addr, boolean isGapAddress) {
Layout layout = layoutCache.get(addr); Layout layout = layoutCache.get(addr, isGapAddress);
if (layout == null) { if (layout == null) {
layout = doGetLayout(addr, isGapAddress); layout = doGetLayout(addr, isGapAddress);
layoutCache.put(addr, layout); layoutCache.put(addr, layout, isGapAddress);
} }
return layout; return layout;
} }
public Layout doGetLayout(Address addr, boolean isGapAddress) { private Layout doGetLayout(Address addr, boolean isGapAddress) {
List<RowLayout> list = new ArrayList<>(); List<RowLayout> list = new ArrayList<>();
FieldFormatModel format; FieldFormatModel format;
CodeUnit cu = listing.getCodeUnitAt(addr); CodeUnit cu = listing.getCodeUnitAt(addr);
@ -581,4 +581,31 @@ public class ProgramBigListingModel implements ListingModel, FormatModelListener
} }
return addressSet; return addressSet;
} }
private class LayoutCache {
private LRUMap<Address, Layout> cache = new LRUMap<>(10);
private LRUMap<Address, Layout> gapCache = new LRUMap<>(10);
void clear() {
cache.clear();
gapCache.clear();
}
Layout get(Address addr, boolean isGapAddress) {
if (isGapAddress) {
return gapCache.get(addr);
}
return cache.get(addr);
}
void put(Address addr, Layout layout, boolean isGapAddress) {
if (isGapAddress) {
gapCache.put(addr, layout);
}
else {
cache.put(addr, layout);
}
}
}
} }