Merge remote-tracking branch 'origin/topic/vlad/snmp_asn1_oid_performance'

* origin/topic/vlad/snmp_asn1_oid_performance:
  Code modernization: use ranged-based for loop where possible
  Improve performance of asn1_oid_to_val string conversions.
This commit is contained in:
Tim Wojtulewicz 2021-09-03 18:10:31 +00:00
commit a54ffd18f3
3 changed files with 10 additions and 9 deletions

View file

@ -1,3 +1,9 @@
4.2.0-dev.106 | 2021-09-03 18:10:31 +0000
* Code modernization: use ranged-based for loop where possible (Vlad Grigorescu)
* Improve performance of asn1_oid_to_val string conversions. (Vlad Grigorescu)
4.2.0-dev.103 | 2021-09-03 18:08:57 +0000 4.2.0-dev.103 | 2021-09-03 18:08:57 +0000
* Disable the scripts.base.frameworks.logging.sqlite.simultaneous-writes test under TSan (Tim Wojtulewicz, Corelight) * Disable the scripts.base.frameworks.logging.sqlite.simultaneous-writes test under TSan (Tim Wojtulewicz, Corelight)

View file

@ -1 +1 @@
4.2.0-dev.103 4.2.0-dev.106

View file

@ -161,9 +161,8 @@ zeek::StringValPtr asn1_oid_to_val(const ASN1Encoding* oid)
// Underflow. // Underflow.
return zeek::val_mgr->EmptyString(); return zeek::val_mgr->EmptyString();
for ( size_t i = 0; i < subidentifiers.size(); ++i ) for ( auto subidentifier : subidentifiers )
{ {
subidentifier = subidentifiers[i];
uint64 value = 0; uint64 value = 0;
for ( size_t j = 0; j < subidentifier.size(); ++j ) for ( size_t j = 0; j < subidentifier.size(); ++j )
@ -183,17 +182,13 @@ zeek::StringValPtr asn1_oid_to_val(const ASN1Encoding* oid)
if ( i > 0 ) if ( i > 0 )
{ {
rval += "."; snprintf(tmp, sizeof(tmp), ".%" PRIu64, subidentifier_values[i]);
snprintf(tmp, sizeof(tmp), "%" PRIu64, subidentifier_values[i]);
rval += tmp; rval += tmp;
} }
else else
{ {
std::div_t result = std::div(subidentifier_values[i], 40); std::div_t result = std::div(subidentifier_values[i], 40);
snprintf(tmp, sizeof(tmp), "%d", result.quot); snprintf(tmp, sizeof(tmp), "%d.%d", result.quot, result.rem);
rval += tmp;
rval += ".";
snprintf(tmp, sizeof(tmp), "%d", result.rem);
rval += tmp; rval += tmp;
} }
} }