GT-2872 - Search - review fixes

This commit is contained in:
dragonmacher 2019-05-16 11:56:33 -04:00
parent 96788aa7fc
commit 8a7a58a297
3 changed files with 31 additions and 11 deletions

View file

@ -55,10 +55,14 @@ import ghidra.util.task.TaskMonitor;
*/ */
public class ProgramDatabaseSearcher implements Searcher { public class ProgramDatabaseSearcher implements Searcher {
private List<ProgramDatabaseFieldSearcher> searchers = new ArrayList<>(); private List<ProgramDatabaseFieldSearcher> searchers = new ArrayList<>();
private Address currentAddress; private Address currentAddress;
private boolean isForward; private boolean isForward;
private SearchOptions searchOptions; private SearchOptions searchOptions;
private long totalSearchCount;
private AddressSet remainingAddresses;
private TaskMonitor monitor; private TaskMonitor monitor;
public ProgramDatabaseSearcher(ServiceProvider serviceProvider, Program program, public ProgramDatabaseSearcher(ServiceProvider serviceProvider, Program program,
@ -74,7 +78,7 @@ public class ProgramDatabaseSearcher implements Searcher {
initialize(serviceProvider, program, startLoc, set, options); initialize(serviceProvider, program, startLoc, set, options);
currentAddress = findNextSignificantAddress(); currentAddress = findNextSignificantAddress();
monitor.initialize(set.getNumAddresses()); monitor.initialize(totalSearchCount);
} }
@Override @Override
@ -105,8 +109,22 @@ public class ProgramDatabaseSearcher implements Searcher {
return; // finished return; // finished
} }
int diff = (int) Math.abs(newAddress.subtract(lastAddress)); AddressSpace lastSpace = lastAddress.getAddressSpace();
monitor.incrementProgress(diff); AddressSpace newSpace = newAddress.getAddressSpace();
if (!lastSpace.equals(newSpace)) {
remainingAddresses.delete(lastSpace.getMinAddress(), lastSpace.getMaxAddress());
}
Address from = newSpace.getMinAddress();
Address to = newAddress.subtract(1);
if (!isForward) {
to = newSpace.getMaxAddress();
from = newAddress.add(1);
}
remainingAddresses.delete(from, to);
long progress = totalSearchCount - remainingAddresses.getNumAddresses();
monitor.setProgress(progress);
} }
@Override @Override
@ -129,6 +147,7 @@ public class ProgramDatabaseSearcher implements Searcher {
nextAddress = isForward ? getMin(nextAddress, nextAddressToCheck) nextAddress = isForward ? getMin(nextAddress, nextAddressToCheck)
: getMax(nextAddress, nextAddressToCheck); : getMax(nextAddress, nextAddressToCheck);
} }
return nextAddress; return nextAddress;
} }
@ -160,6 +179,8 @@ public class ProgramDatabaseSearcher implements Searcher {
AddressSetView trimmedSet = adjustSearchSet(program, start, view, forward); AddressSetView trimmedSet = adjustSearchSet(program, start, view, forward);
ProgramLocation adjustedStart = adjustStartLocation(program, start, trimmedSet, forward); ProgramLocation adjustedStart = adjustStartLocation(program, start, trimmedSet, forward);
remainingAddresses = new AddressSet(trimmedSet);
totalSearchCount = trimmedSet.getNumAddresses();
Pattern pattern = Pattern pattern =
UserSearchUtils.createSearchPattern(options.getText(), options.isCaseSensitive()); UserSearchUtils.createSearchPattern(options.getText(), options.isCaseSensitive());

View file

@ -165,12 +165,11 @@ public interface Address extends Comparable<Address> {
public int getSize(); public int getSize();
/** /**
* Calculates the displacement between two addresses (<code>this - * Calculates the displacement between two addresses (<code>this - addr</code>)
* addr</code>).
*
* @param addr the Address to subtract from <code>this</code> address.
* @return the difference. (thisAddress.offset - thatAddress.offset
* *
* @param addr the Address to subtract from <code>this</code> address
* @return the difference (thisAddress.offset - thatAddress.offset)
* @throws IllegalArgumentException if the two addresses are not in the same address space
*/ */
public long subtract(Address addr); public long subtract(Address addr);

View file

@ -29,7 +29,7 @@ import ghidra.util.datastruct.RedBlackTree;
public class AddressSet implements AddressSetView { public class AddressSet implements AddressSetView {
private final static double LOGBASE2 = Math.log(2); private final static double LOGBASE2 = Math.log(2);
private RedBlackTree<Address, Address> rbTree = new RedBlackTree<Address, Address>(); private RedBlackTree<Address, Address> rbTree = new RedBlackTree<>();
private RedBlackEntry<Address, Address> lastNode; private RedBlackEntry<Address, Address> lastNode;
private long addressCount = 0; private long addressCount = 0;
@ -282,7 +282,7 @@ public class AddressSet implements AddressSetView {
/** /**
* Deletes a range of addresses from this set * Deletes a range of addresses from this set
* @param start the starting address of the range to be removed * @param start the starting address of the range to be removed
* @param end the ending address of the range to be removed * @param end the ending address of the range to be removed (inclusive)
*/ */
public final void delete(Address start, Address end) { public final void delete(Address start, Address end) {
if (start.compareTo(end) > 0) { if (start.compareTo(end) > 0) {
@ -403,7 +403,7 @@ public class AddressSet implements AddressSetView {
* @return a list of the AddressRanges in this set. * @return a list of the AddressRanges in this set.
*/ */
public List<AddressRange> toList() { public List<AddressRange> toList() {
ArrayList<AddressRange> list = new ArrayList<AddressRange>(); ArrayList<AddressRange> list = new ArrayList<>();
for (AddressRange range : this) { for (AddressRange range : this) {
list.add(range); list.add(range);
} }