Skip to content

Commit 5fa68f4

Browse files
GillesDuvertGiloo
andauthored
Sort extra tags closes #2074 (#2080)
Co-authored-by: Giloo <gildas@localhost>
1 parent 7372fc2 commit 5fa68f4

File tree

1 file changed

+9
-36
lines changed

1 file changed

+9
-36
lines changed

src/extrat.cpp

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -213,53 +213,26 @@ void ExtraT::ResolveExtra(EnvBaseT* callerIn) {
213213

214214
// from back -> _EXTRA overrides additional keyword
215215
//GD: Protect (do not throw) against !NULL -valued tags. These ARE included in _REF_EXTRA and should not appear in _EXTRA, but
216-
//GDL shoudl not throw on them.
216+
//GDL should not throw on them.
217+
//GD: EXTRA Struct tags are sorted (issue #2074)
218+
std::map<std::string, BaseGDL*>entries;
217219
for (int i = nEl - 1; i >= 0; --i) {
218220
if (listEnv[i] != NULL && listEnv.IsDefined(i)) // if undef or !NULL just skip (pass by value)
219221
{
220-
if (extraStruct == NULL) {
221-
extraStructDesc = new DStructDesc("$truct");
222-
// extraStruct = new DStructGDL( extraStructDesc, dimension(1));
223-
extraStruct = new DStructGDL(extraStructDesc);
224-
225-
// extraStructDesc->AddTag( listName[i], listEnv[i]);
226-
// extraStruct->AddTagGrab( listEnv.Grab(i));
227-
extraStruct->NewTag(listName[i], listEnv.Grab(i));
228-
} else
229-
if (extraStructDesc->TagIndex(listName[i]) == -1) {
230-
extraStruct->NewTag(listName[i], listEnv.Grab(i));
231-
// extraStructDesc->AddTag( listName[i], listEnv[i]);
232-
// extraStruct->AddTagGrab( listEnv.Grab(i));
233-
// extraStruct->AddTag( listEnv[i]);
234-
}
222+
if (entries.find(listName[i]) == entries.end()) entries[listName[i]]=listEnv.Grab(i);
235223
}
236224
}
237-
238-
// look if equal is already there (very possible eg. _EXTRA in loops)
239-
// DStructDesc* oStructDesc=extraStructDesc->FindEqual( structList);
240-
// if( oStructDesc != NULL)
241-
// {
242-
// extraStruct->SetDesc(oStructDesc);
243-
// delete extraStructDesc;
244-
// }
245-
// else
246-
// {
247-
// // insert into struct list // NOT ANYMORE!!!
248-
// structList.push_back( extraStructDesc);
249-
// }
250-
251-
// structList.push_back( extraStructDesc);
252-
225+
extraStructDesc = new DStructDesc("$truct");
226+
extraStruct = new DStructGDL(extraStructDesc);
227+
if (!entries.empty()) { //dumb protection?
228+
for (std::map<std::string, BaseGDL*>::iterator it=entries.begin(); it!=entries.end(); ++it) extraStruct->NewTag(it->first, it->second);
229+
}
253230

254231
assert(thisEnv->env.Loc(static_cast<SizeT> (pro->extraIx)) == NULL);
255232
assert(thisEnv->env.Env(static_cast<SizeT> (pro->extraIx)) == NULL);
256233

257234
thisEnv->env.Set(static_cast<SizeT> (pro->extraIx),
258235
static_cast<BaseGDL*> (extraStruct));
259-
260-
261-
// thisEnv->env.Reset( static_cast<SizeT>(pro->extraIx),
262-
// static_cast<BaseGDL*>(extraStruct));
263236
}
264237
}
265238
}

0 commit comments

Comments
 (0)