Skip to content

Commit

Permalink
[core] Put CSrtConfigSetter into anonymous namespace
Browse files Browse the repository at this point in the history
And use simple switch case. The library size is reduced from 1224 KB
to 1216 KB on macOS build with:
-DENABLE_TESTING=ON -DENABLE_UNITTESTS=ON -DENABLE_HEAVY_LOGGING=ON \
-DUSE_ENCLIB=mbedtls -DENABLE_EXPERIMENTAL_BONDING=ON -DENABLE_ENCRYPTION=OFF \
-DENABLE_STDCXX_SYNC=ON
  • Loading branch information
quink-black authored and maxsharabayko committed Jul 26, 2021
1 parent 589f103 commit 127c85c
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions srtcore/socketconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ written by

extern const int32_t SRT_DEF_VERSION = SrtParseVersion(SRT_VERSION);

namespace {
typedef void setter_function(CSrtConfig& co, const void* optval, int optlen);

template<SRT_SOCKOPT name>
Expand Down Expand Up @@ -872,15 +873,11 @@ struct CSrtConfigSetter<SRTO_RETRANSMITALGO>
}
};

static struct SrtConfigSetter
int dispatchSet(SRT_SOCKOPT optName, CSrtConfig& co, const void* optval, int optlen)
{
setter_function* fn[SRTO_E_SIZE];

SrtConfigSetter()
switch (optName)
{
memset(fn, 0, sizeof fn);

#define DISPATCH(optname) fn[optname] = &CSrtConfigSetter<optname>::set;
#define DISPATCH(optname) case optname: CSrtConfigSetter<optname>::set(co, optval, optlen); return 0;

DISPATCH(SRTO_MSS);
DISPATCH(SRTO_FC);
Expand Down Expand Up @@ -937,17 +934,16 @@ static struct SrtConfigSetter
DISPATCH(SRTO_RETRANSMITALGO);

#undef DISPATCH
default:
return -1;
}
} srt_config_setter;
}

} // anonymous namespace

int CSrtConfig::set(SRT_SOCKOPT optName, const void* optval, int optlen)
{
setter_function* fn = srt_config_setter.fn[optName];
if (!fn)
return -1; // No such option

fn(*this, optval, optlen); // MAY THROW EXCEPTION.
return 0;
return dispatchSet(optName, *this, optval, optlen);
}

#if ENABLE_EXPERIMENTAL_BONDING
Expand Down

0 comments on commit 127c85c

Please sign in to comment.