Skip to content

Commit 5365728

Browse files
committed
[SharedCache] Use StringRef for performance
1 parent 1925885 commit 5365728

File tree

5 files changed

+9
-8
lines changed

5 files changed

+9
-8
lines changed

view/sharedcache/api/sharedcache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ namespace SharedCacheAPI {
165165
{
166166
DSCSymbol sym;
167167
sym.address = value[i].address;
168-
sym.name = value[i].name;
168+
sym.name = StringRef(BNDuplicateStringRef(value[i].name));
169169
sym.image = value[i].image;
170170
result.push_back(sym);
171171
}

view/sharedcache/api/sharedcacheapi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace SharedCacheAPI {
126126

127127
struct DSCSymbol {
128128
uint64_t address;
129-
std::string name;
129+
BinaryNinja::StringRef name;
130130
std::string image;
131131
};
132132

view/sharedcache/api/sharedcachecore.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ extern "C"
6666

6767
typedef struct BNBinaryView BNBinaryView;
6868
typedef struct BNSharedCache BNSharedCache;
69+
typedef struct BNStringRef BNStringRef;
6970

7071
typedef struct BNDSCImageMemoryMapping {
7172
char* filePath;
@@ -109,7 +110,7 @@ extern "C"
109110

110111
typedef struct BNDSCSymbolRep {
111112
uint64_t address;
112-
char* name;
113+
BNStringRef* name;
113114
char* image;
114115
} BNDSCSymbolRep;
115116

view/sharedcache/core/SharedCache.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3154,7 +3154,7 @@ extern "C"
31543154
for (size_t i = 0; i < value.size(); i++)
31553155
{
31563156
symbols[i].address = value[i].second->GetAddress();
3157-
symbols[i].name = BNAllocString(value[i].second->GetRawName().c_str());
3157+
symbols[i].name = BNDuplicateStringRef(value[i].second->GetRawNameRef().GetObject());
31583158
symbols[i].image = BNAllocString(value[i].first.c_str());
31593159
}
31603160
return symbols;
@@ -3167,7 +3167,7 @@ extern "C"
31673167
{
31683168
for (size_t i = 0; i < count; i++)
31693169
{
3170-
BNFreeString(symbols[i].name);
3170+
BNFreeStringRef(symbols[i].name);
31713171
BNFreeString(symbols[i].image);
31723172
}
31733173
delete symbols;
@@ -3468,7 +3468,7 @@ void SharedCache::Store(SerializationContext& context) const
34683468
context.writer.StartObject();
34693469
Serialize(context, "key", pair2.first);
34703470
Serialize(context, "val1", pair2.second->GetType());
3471-
Serialize(context, "val2", pair2.second->GetRawName());
3471+
Serialize(context, "val2", (std::string_view)pair2.second->GetRawNameRef());
34723472
context.writer.EndObject();
34733473
}
34743474
context.writer.EndArray();

view/sharedcache/ui/dsctriage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ QVariant SymbolTableModel::data(const QModelIndex& index, int role) const {
422422
case 0: // Address column
423423
return QString("0x%1").arg(symbol.address, 0, 16); // Display address as hexadecimal
424424
case 1: // Name column
425-
return QString::fromStdString(symbol.name);
425+
return QString::fromUtf8(symbol.name.c_str(), symbol.name.size());
426426
case 2: // Image column
427427
return QString::fromStdString(symbol.image);
428428
default:
@@ -473,7 +473,7 @@ void SymbolTableModel::setFilter(std::string text)
473473
m_symbols.reserve(m_parent->m_symbols.size());
474474
for (const auto& symbol : m_parent->m_symbols)
475475
{
476-
if (symbol.name.find(m_filter) != std::string::npos)
476+
if (((std::string_view)symbol.name).find(m_filter) != std::string::npos)
477477
{
478478
m_symbols.push_back(symbol);
479479
}

0 commit comments

Comments
 (0)