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

Use emplace correctly and use RVO #78

Merged
merged 1 commit into from
Sep 20, 2024
Merged
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
17 changes: 6 additions & 11 deletions lib/libpcsc-cpp/src/listReaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,6 @@ inline flag_set<Reader::Status> flagSetFromReaderState(const DWORD readerState)
return result;
}

inline Reader makeReader(const ContextPtr& ctx, const SCARD_READERSTATE& readerState)
{
return Reader {ctx, readerState.szReader,
byte_vector {readerState.rgbAtr, readerState.rgbAtr + readerState.cbAtr},
flagSetFromReaderState(readerState.dwEventState)};
}

string_t populateReaderNames(const SCARDCONTEXT ctx)
{
// Buffer length is in characters, not bytes.
Expand All @@ -142,18 +135,20 @@ namespace pcsc_cpp
std::vector<Reader> listReaders()
{
auto ctx = std::make_shared<Context>();
std::vector<Reader> readers;

try {
auto readerNames = populateReaderNames(ctx->handle());

auto readers = std::vector<Reader> {};
for (const auto& readerState : getReaderStates(ctx->handle(), readerNames)) {
readers.emplace_back(makeReader(ctx, readerState));
readers.emplace_back(
ctx, readerState.szReader,
byte_vector {readerState.rgbAtr, std::next(readerState.rgbAtr, readerState.cbAtr)},
flagSetFromReaderState(readerState.dwEventState));
}
return readers;
} catch (const ScardNoReadersError& /* e */) {
return std::vector<Reader> {};
}
return readers;
}

} // namespace pcsc_cpp
Loading