GT-3341_emteere_RTTIPerformance Code Review changes

This commit is contained in:
emteere 2020-02-18 21:11:37 +00:00
parent b51a9d7ff4
commit edfff3a267
5 changed files with 15 additions and 56 deletions

View file

@ -15,7 +15,7 @@
*/
package ghidra.app.cmd.data.rtti;
import static ghidra.app.util.datatype.microsoft.MSDataTypeUtils.getAbsoluteAddress;
import static ghidra.app.util.datatype.microsoft.MSDataTypeUtils.*;
import ghidra.app.cmd.data.*;
import ghidra.app.util.datatype.microsoft.DataApplyOptions;
@ -172,9 +172,8 @@ public class CreateVfTableBackgroundCmd extends AbstractCreateDataBackgroundCmd<
if (rtti0Model != null) {
// Plate Comment
EHDataTypeUtilities.createPlateCommentIfNeeded(program,
RttiUtil.CONST_PREFIX + RttiUtil.getDescriptorTypeNamespace(rtti0Model) +
Namespace.DELIMITER,
EHDataTypeUtilities.createPlateCommentIfNeeded(program, RttiUtil.CONST_PREFIX +
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER,
VF_TABLE_LABEL, null, vfTableAddress, applyOptions);
monitor.checkCanceled();
@ -188,7 +187,7 @@ public class CreateVfTableBackgroundCmd extends AbstractCreateDataBackgroundCmd<
// Create functions that are referred to by the vf table.
if (applyOptions.shouldCreateFunction()) {
int elementCount = model.getElementCount();
int elementCount = model.getCount();
for (int tableElementIndex = 0; tableElementIndex < elementCount; tableElementIndex++) {
monitor.checkCanceled();
Address vfPointer = model.getVirtualFunctionPointer(tableElementIndex);

View file

@ -40,7 +40,6 @@ public class VfTableModel extends AbstractCreateDataTypeModel {
private DataType dataType;
private Rtti4Model rtti4Model;
private int elementCount = -1;
private Program lastProgram;
private DataType lastDataType;
@ -57,8 +56,6 @@ public class VfTableModel extends AbstractCreateDataTypeModel {
DataValidationOptions validationOptions) {
super(program, RttiUtil.getVfTableCount(program, vfTableAddress), vfTableAddress,
validationOptions);
// super's count will hold the number of valid address elements from getVfTableCount()
elementCount = getCount();
}
@Override
@ -82,7 +79,7 @@ public class VfTableModel extends AbstractCreateDataTypeModel {
long entrySize = individualEntryDataType.getLength();
// Each entry is a pointer to where a function can possibly be created.
long numEntries = getElementCount();
long numEntries = getCount();
if (numEntries == 0) {
throw new InvalidDataTypeException(
getName() + " data type at " + getAddress() + " doesn't have a valid vf table.");
@ -125,7 +122,7 @@ public class VfTableModel extends AbstractCreateDataTypeModel {
lastDataType = null;
lastElementCount = -1;
lastElementCount = getElementCount();
lastElementCount = getCount();
if (lastElementCount > 0) {
DataTypeManager dataTypeManager = program.getDataTypeManager();
PointerDataType pointerDt = new PointerDataType(dataTypeManager);
@ -170,17 +167,6 @@ public class VfTableModel extends AbstractCreateDataTypeModel {
return getAbsoluteAddress(getProgram(), address);
}
/**
* Gets the number of elements in the vf table. Returns 0 if this model isn't for a valid vf table.
* @return the number of vf table elements or 0.
*/
public int getElementCount() {
if (elementCount == -1) {
elementCount = RttiUtil.getVfTableCount(getProgram(), getAddress());
}
return elementCount;
}
/**
* Gets the type descriptor (RTTI 0) model associated with this vf table.
* @return the type descriptor (RTTI 0) model or null.