some time ago i sat and read assoc.cc
i found several similar places with strange constructions:
for example in very important function ASC_findAcceptedPresentationContextID
----------------------------------------
while (pc && !found)
{
found = (strcmp(pc->abstractSyntax, abstractSyntax) == 0);
found &= (pc->result == ASC_P_ACCEPTANCE);
found &= ((strcmp(pc->acceptedTransferSyntax, UID_LittleEndianExplicitTransferSyntax) == 0) ||
(strcmp(pc->acceptedTransferSyntax, UID_BigEndianExplicitTransferSyntax) == 0));
if (!found) pc = (DUL_PRESENTATIONCONTEXT*) LST_Next(l);
}
-----------------------------------------
first, &= is bitwise operator, it will work for OFBool - agree, but it degrades performance of assoc functions.
every iteration will run 3 strcmp and 1 "==" but it is absolutely unnecessary!
mb better to rewrite it as:
{
found = (strcmp(pc->abstractSyntax, abstractSyntax) == 0) &&
(pc->result == ASC_P_ACCEPTANCE) && ((strcmp(pc->acceptedTransferSyntax, UID_LittleEndianExplicitTransferSyntax) == 0) || (strcmp(pc->acceptedTransferSyntax, UID_BigEndianExplicitTransferSyntax) == 0));
if (!found) pc = (DUL_PRESENTATIONCONTEXT*) LST_Next(l);
}
in this case we'll run only "true" statements and will stop right after first "false" found. most of iterations will execute only first (strcmp(pc->abstractSyntax, abstractSyntax) == 0)
strcmp is VERY expensive for cpu
thanks!
some suggestions about optimization
Moderator: Moderator Team
-
- DCMTK Developer
- Posts: 2055
- Joined: Fri, 2004-11-05, 13:47
- Location: Oldenburg, Germany
- Contact:
Re: some suggestions about optimization
Hi Shaeto,
Best re
Well, always a source for mysterious old code... -- We are happy that you take time to check through this jungleShaeto wrote:some time ago i sat and read assoc.cc
Good point! I changed the code according to your proposal. Thanks for the suggestion, I hope I changed all occurences.i found several similar places with strange constructions:
for example in very important function ASC_findAcceptedPresentationContextID
[..]
mb better to rewrite it as:
{
found = (strcmp(pc->abstractSyntax, abstractSyntax) == 0) &&
(pc->result == ASC_P_ACCEPTANCE) && ((strcmp(pc->acceptedTransferSyntax, UID_LittleEndianExplicitTransferSyntax) == 0) || (strcmp(pc->acceptedTransferSyntax, UID_BigEndianExplicitTransferSyntax) == 0));
if (!found) pc = (DUL_PRESENTATIONCONTEXT*) LST_Next(l);
}
Best re
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest