Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the list of global elements non recursive #283

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/EbmlContexts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ DEFINE_SEMANTIC_ITEM(false, false, EbmlCrc32)
DEFINE_SEMANTIC_ITEM(false, false, EbmlVoid)
DEFINE_END_SEMANTIC(EbmlGlobal)

static DEFINE_xxx_CONTEXT(EbmlGlobal, GetEbmlGlobal_Context)
static DEFINE_xxx_CONTEXT(EbmlGlobal, nullptr)

const EbmlSemanticContext & GetEbmlGlobal_Context()
{
Expand Down
50 changes: 25 additions & 25 deletions src/EbmlElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@ EbmlElement * EbmlElement::SkipData(EbmlStream & DataStream, const EbmlSemanticC
/////////////////////////////////////////////////
// read elements until an upper element is found
/////////////////////////////////////////////////
bool bEndFound = false;
while (!bEndFound && Result == nullptr) {
while (Result == nullptr) {
// read an element
/// \todo 0xFF... and true should be configurable
// EbmlElement * NewElt;
Expand All @@ -386,31 +385,29 @@ EbmlElement * EbmlElement::SkipData(EbmlStream & DataStream, const EbmlSemanticC
TestReadElt = nullptr;
}

if (Result != nullptr) {
unsigned int EltIndex;
// data known in this Master's context
for (EltIndex = 0; EltIndex < EBML_CTX_SIZE(Context); EltIndex++) {
if (EbmlId(*Result) == EBML_CTX_IDX_ID(Context,EltIndex)) {
// skip the data with its own context
Result = Result->SkipData(DataStream, EBML_SEM_CONTEXT(EBML_CTX_IDX(Context,EltIndex)), nullptr);
break; // let's go to the next ID
}
if (Result == nullptr)
break;

unsigned int EltIndex;
// data known in this Master's context
for (EltIndex = 0; EltIndex < EBML_CTX_SIZE(Context); EltIndex++) {
if (EbmlId(*Result) == EBML_CTX_IDX_ID(Context,EltIndex)) {
// skip the data with its own context
assert(&EBML_SEM_CONTEXT(EBML_CTX_IDX(Context,EltIndex)) == &EBML_CONTEXT(Result));
Result = Result->SkipData(DataStream, EBML_CONTEXT(Result), nullptr);
break; // let's go to the next ID
}
}

if (EltIndex >= EBML_CTX_SIZE(Context)) {
if (EBML_CTX_PARENT(Context) != nullptr) {
Result = SkipData(DataStream, *EBML_CTX_PARENT(Context), Result);
} else {
assert(Context.GetGlobalContext != nullptr);
if (Context != Context.GetGlobalContext()) {
Result = SkipData(DataStream, Context.GetGlobalContext(), Result);
} else {
bEndFound = true;
}
}
if (EltIndex >= EBML_CTX_SIZE(Context)) {
if (EBML_CTX_PARENT(Context) != nullptr) {
// the element found is a parent of the original provided Context
// skip all its data as well (?!!!) until there's nothing to skip at that level
Result = SkipData(DataStream, *EBML_CTX_PARENT(Context), Result);
} else {
// we found a global element
Result = SkipData(DataStream, EBML_CONTEXT(Result), Result);
}
} else {
bEndFound = true;
}
}
}
Expand All @@ -435,8 +432,11 @@ EbmlElement *EbmlElement::CreateElementUsingContext(const EbmlId & aID, const Eb
}
}

if (Context.GetGlobalContext == nullptr)
// this is a already the global EbmlSemanticContext, if it's the last one and we
// didn't find our global elements, we won't find anything anymore
return nullptr;
// global elements
assert(Context.GetGlobalContext != nullptr); // global should always exist, at least the EBML ones
const auto& tstContext = Context.GetGlobalContext();
if (tstContext != Context) {
LowLevel--;
Expand Down