Skip to content

Commit

Permalink
Avoid list iteration in dynInterface_nrOfMethods.
Browse files Browse the repository at this point in the history
  • Loading branch information
PengZheng committed Jan 22, 2024
1 parent 1220311 commit 74f1243
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
6 changes: 3 additions & 3 deletions libs/dfi/gtest/descriptors/example6.descriptor
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
:header
type=interface
name=example6
name=calculator
version=1.0.0
:annotations
classname=org.example.Calculator
:types
CptData={Dt[D#v1=1;#v2=2;E d t s e}
StatsResult={DDD[D average min max input}
:methods
compatibility=cpt(#am=handle;PLCptData;#am=out;*LCptData;)N
24 changes: 24 additions & 0 deletions libs/dfi/gtest/src/dyn_interface_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,27 @@ TEST_F(DynInterfaceTests, testInvalid) {
testInvalid();
}


TEST_F(DynInterfaceTests, testEmptyMethod) {
int status = 0;
dyn_interface_type *dynIntf = NULL;
FILE *desc = fopen("descriptors/example6.descriptor", "r");
assert(desc != NULL);
status = dynInterface_parse(desc, &dynIntf);
ASSERT_EQ(0, status);
fclose(desc);

const char *name = dynInterface_getName(dynIntf);
ASSERT_STREQ("calculator", name);

checkInterfaceVersion(dynIntf,"1.0.0");

const struct methods_head* list = dynInterface_methods(dynIntf);
ASSERT_TRUE(list != NULL);

int count = dynInterface_nrOfMethods(dynIntf);
ASSERT_EQ(0, count);

dynInterface_destroy(dynIntf);
}

8 changes: 2 additions & 6 deletions libs/dfi/src/dyn_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ const struct methods_head* dynInterface_methods(const dyn_interface_type* intf)
}

int dynInterface_nrOfMethods(const dyn_interface_type* intf) {
int count = 0;
struct method_entry* entry = NULL;
TAILQ_FOREACH(entry, &intf->methods, entries) {
count +=1;
}
return count;
struct method_entry* last = TAILQ_LAST(&intf->methods, methods_head);
return last == NULL ? 0 : (last->index+1);
}

0 comments on commit 74f1243

Please sign in to comment.