DCOUT now only prints when TINYUSDZ_ENABLE_DCOUT env is set.

move optimization
This commit is contained in:
Syoyo Fujita
2025-10-08 02:58:03 +09:00
parent 72bebda8d0
commit 296c825820
5 changed files with 47 additions and 28 deletions

View File

@@ -1,6 +1,7 @@
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
@@ -75,6 +76,13 @@ void print_help() {
}
int main(int argc, char **argv) {
// Enable DCOUT output if TINYUSDZ_ENABLE_DCOUT environment variable is set
const char* enable_dcout_env = std::getenv("TINYUSDZ_ENABLE_DCOUT");
if (enable_dcout_env != nullptr && std::strlen(enable_dcout_env) > 0) {
// Any non-empty value enables DCOUT
tinyusdz::g_enable_dcout_output = true;
}
if (argc < 2) {
print_help();
return EXIT_FAILURE;

View File

@@ -4,6 +4,11 @@
#include <sstream>
#include <string>
// Global flag to control DCOUT output. Set via TINYUSDZ_ENABLE_DCOUT environment variable.
namespace tinyusdz {
extern bool g_enable_dcout_output;
}
#if !defined(TINYUSDZ_PRODUCTION_BUILD) && !defined(TINYUSDZ_FUZZER_BUILD)
#if defined(TINYUSDZ_DEBUG_PRINT)
#define TINYUSDZ_LOCAL_DEBUG_PRINT
@@ -93,8 +98,10 @@
#if defined(TINYUSDZ_LOCAL_DEBUG_PRINT)
#define DCOUT(x) \
do { \
std::cout << __FILE__ << ":" << __func__ << ":" \
<< std::to_string(__LINE__) << " " << x << "\n"; \
if (tinyusdz::g_enable_dcout_output) { \
std::cout << __FILE__ << ":" << __func__ << ":" \
<< std::to_string(__LINE__) << " " << x << "\n"; \
} \
} while (false)
#else
#define DCOUT(x)

View File

@@ -391,7 +391,7 @@ class CrateValue {
//std::string GetTypeName() const;
//uint32_t GetTypeId() const;
#define SET_TYPE_SCALAR(__ty) void Set(const __ty& v) { TUSDZ_LOG_I("copy set"); value_ = v; } void Set(__ty&& v) { TUSDZ_LOG_I("move set"); value::Value src(std::move(v)); value_ = std::move(src); }
#define SET_TYPE_SCALAR(__ty) void Set(const __ty& v) { value_ = v; } void Set(__ty&& v) { value::Value src(std::move(v)); value_ = std::move(src); }
//#define MOVE_SET_TYPE_SCALAR(__ty) void MoveSet(__ty&& v) { TUSDZ_LOG_I("move set"); value::Value src(std::move(v)); value_ = std::move(src); }
#define SET_TYPE_1D(__ty) void Set(const std::vector<__ty> &v) { value_ = v; }
@@ -469,7 +469,7 @@ class CrateValue {
SET_TYPE_LIST(SET_TYPE_1D)
//SET_TYPE_LIST(MOVE_SET_TYPE_1D)
SET_TYPE_LIST(MOVE_SET_TYPE_1D)
// TypedArray Set methods for efficient array handling with mmap support
#define SET_TYPE_TYPED_ARRAY(__ty) void Set(const TypedArray<__ty> &v) { value_ = v; }

View File

@@ -5121,7 +5121,7 @@ bool CrateReader::UnpackValueRepForTimeSamples(const crate::ValueRep &rep, uint6
}
}
if (n == 0) {
value->Set(v);
value->Set(std::move(v));
return true;
}
if (n > _config.maxArrayElements) {
@@ -5177,7 +5177,7 @@ bool CrateReader::UnpackValueRepForTimeSamples(const crate::ValueRep &rep, uint6
}
}
if (n == 0) {
value->Set(v);
value->Set(std::move(v));
return true;
}
if (n > _config.maxArrayElements) {
@@ -5233,7 +5233,7 @@ bool CrateReader::UnpackValueRepForTimeSamples(const crate::ValueRep &rep, uint6
}
}
if (n == 0) {
value->Set(v);
value->Set(std::move(v));
return true;
}
if (n > _config.maxArrayElements) {
@@ -5513,7 +5513,7 @@ bool CrateReader::UnpackValueRepForTimeSamples(const crate::ValueRep &rep, uint6
bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
crate::CrateValue *value) {
TUSDZ_LOG_I("unpack . ty " << GetCrateDataTypeName(rep.GetType()) << ", inlined " << rep.IsInlined());
//TUSDZ_LOG_I("unpack . ty " << GetCrateDataTypeName(rep.GetType()) << ", inlined " << rep.IsInlined());
if (rep.IsInlined()) {
return UnpackInlinedValueRep(rep, value);
@@ -5577,7 +5577,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
std::vector<bool> v;
if (rep.GetPayload() == 0) { // empty array
value->Set(v);
value->Set(std::move(v));
return true;
}
@@ -5811,7 +5811,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
if (rep.IsArray()) {
std::vector<int32_t> v;
if (rep.GetPayload() == 0) { // empty array
value->Set(v);
value->Set(std::move(v));
return true;
}
if (!ReadIntArray(rep.IsCompressed(), &v)) {
@@ -5838,7 +5838,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
if (rep.IsArray()) {
std::vector<uint32_t> v;
if (rep.GetPayload() == 0) { // empty array
value->Set(v);
value->Set(std::move(v));
return true;
}
if (!ReadIntArray(rep.IsCompressed(), &v)) {
@@ -5863,7 +5863,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
if (rep.IsArray()) {
std::vector<int64_t> v;
if (rep.GetPayload() == 0) { // empty array
value->Set(v);
value->Set(std::move(v));
return true;
}
if (!ReadIntArray(rep.IsCompressed(), &v)) {
@@ -5902,7 +5902,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
if (rep.IsArray()) {
std::vector<uint64_t> v;
if (rep.GetPayload() == 0) { // empty array
value->Set(v);
value->Set(std::move(v));
return true;
}
@@ -5942,7 +5942,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
if (rep.IsArray()) {
std::vector<value::half> v;
if (rep.GetPayload() == 0) { // empty array
value->Set(v);
value->Set(std::move(v));
return true;
}
if (!ReadHalfArray(rep.IsCompressed(), &v)) {
@@ -6026,7 +6026,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
if (rep.IsArray()) {
std::vector<value::matrix2d> v;
if (rep.GetPayload() == 0) { // empty array
value->Set(v);
value->Set(std::move(v));
return true;
}
@@ -6051,7 +6051,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
}
if (n == 0) {
value->Set(v);
value->Set(std::move(v));
return true;
}
@@ -6097,7 +6097,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
if (rep.IsArray()) {
std::vector<value::matrix3d> v;
if (rep.GetPayload() == 0) { // empty array
value->Set(v);
value->Set(std::move(v));
return true;
}
@@ -6122,7 +6122,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
}
if (n == 0) {
value->Set(v);
value->Set(std::move(v));
return true;
}
@@ -6168,7 +6168,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
if (rep.IsArray()) {
std::vector<value::matrix4d> v;
if (rep.GetPayload() == 0) { // empty array
value->Set(v);
value->Set(std::move(v));
return true;
}
@@ -6193,7 +6193,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
}
if (n == 0) {
value->Set(v);
value->Set(std::move(v));
return true;
}
@@ -6236,7 +6236,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
if (rep.IsArray()) {
std::vector<value::quatd> v;
if (rep.GetPayload() == 0) { // empty array
value->Set(v);
value->Set(std::move(v));
return true;
}
uint64_t n{0};
@@ -6260,7 +6260,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
}
if (n == 0) {
value->Set(v);
value->Set(std::move(v));
return true;
}
@@ -6304,7 +6304,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
if (rep.IsArray()) {
std::vector<value::quatf> v;
if (rep.GetPayload() == 0) { // empty array
value->Set(v);
value->Set(std::move(v));
return true;
}
uint64_t n{0};
@@ -6328,7 +6328,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
}
if (n == 0) {
value->Set(v);
value->Set(std::move(v));
return true;
}
@@ -6372,7 +6372,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
if (rep.IsArray()) {
std::vector<value::quath> v;
if (rep.GetPayload() == 0) { // empty array
value->Set(v);
value->Set(std::move(v));
return true;
}
@@ -6397,7 +6397,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
}
if (n == 0) {
value->Set(v);
value->Set(std::move(v));
return true;
}
@@ -6697,7 +6697,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
if (rep.IsArray()) {
std::vector<value::int2> v;
if (rep.GetPayload() == 0) { // empty array
value->Set(v);
value->Set(std::move(v));
return true;
}
@@ -7343,7 +7343,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,
if (rep.IsArray()) {
std::vector<value::int4> v;
if (rep.GetPayload() == 0) { // empty array
value->Set(v);
value->Set(std::move(v));
return true;
}
uint64_t n{0};

View File

@@ -68,6 +68,10 @@
namespace tinyusdz {
// Global flag to control DCOUT output. Defaults to false to suppress flood of output.
// Set to true via TINYUSDZ_ENABLE_DCOUT environment variable.
bool g_enable_dcout_output = false;
// constexpr auto kTagUSDA = "[USDA]";
// constexpr auto kTagUSDC = "[USDC]";
// constexpr auto kTagUSDZ = "[USDZ]";