aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicole Mazzuca <t-nimaz@microsoft.com>2019-07-11 10:53:32 -0700
committerNicole Mazzuca <t-nimaz@microsoft.com>2019-07-11 18:20:36 -0700
commit319023587558a9f8de9d7eabeb7441ef2e7ee277 (patch)
tree0b7672db03a2ccf3d6dbb399c4643468cf3c37e6
parentbb579072077153fabfa74acec852bce222265357 (diff)
downloadvcpkg-319023587558a9f8de9d7eabeb7441ef2e7ee277.tar.gz
vcpkg-319023587558a9f8de9d7eabeb7441ef2e7ee277.zip
fix some comments from code reviewers
-rw-r--r--toolsrc/include/vcpkg/base/strings.h10
-rw-r--r--toolsrc/include/vcpkg/base/work_queue.h15
2 files changed, 13 insertions, 12 deletions
diff --git a/toolsrc/include/vcpkg/base/strings.h b/toolsrc/include/vcpkg/base/strings.h
index 9890bedbc..25cd302b0 100644
--- a/toolsrc/include/vcpkg/base/strings.h
+++ b/toolsrc/include/vcpkg/base/strings.h
@@ -208,11 +208,13 @@ namespace vcpkg::Strings
std::string result;
// reserve ceiling(number of bits / 3)
- result.reserve((sizeof(value) * 8 + 2) / 3);
+ result.resize((sizeof(value) * 8 + 2) / 3, map[0]);
- while (value != 0) {
- char mapped_value = map[value & mask];
- result.push_back(mapped_value);
+ for (char& c: result) {
+ if (value == 0) {
+ break;
+ }
+ c = map[value & mask];
value >>= shift;
}
diff --git a/toolsrc/include/vcpkg/base/work_queue.h b/toolsrc/include/vcpkg/base/work_queue.h
index 8a3d27538..b6f070cd8 100644
--- a/toolsrc/include/vcpkg/base/work_queue.h
+++ b/toolsrc/include/vcpkg/base/work_queue.h
@@ -11,7 +11,7 @@ namespace vcpkg {
namespace detail {
// for SFINAE purposes, keep out of the class
template <class Action, class ThreadLocalData>
- auto call_action(
+ auto call_moved_action(
Action& action,
const WorkQueue<Action, ThreadLocalData>& work_queue,
ThreadLocalData& tld
@@ -21,7 +21,7 @@ namespace vcpkg {
}
template <class Action, class ThreadLocalData>
- auto call_action(
+ auto call_moved_action(
Action& action,
const WorkQueue<Action, ThreadLocalData>&,
ThreadLocalData& tld
@@ -134,21 +134,18 @@ namespace vcpkg {
ThreadLocalData tld;
void operator()() {
- // unlocked when waiting, or when in the `call_action` block
+ // unlocked when waiting, or when in the `call_moved_action`
+ // block
// locked otherwise
auto lck = std::unique_lock<std::mutex>(work_queue->m_mutex);
for (;;) {
- ++work_queue->running_workers;
-
const auto state = work_queue->m_state;
if (state == State::Terminated) {
- --work_queue->running_workers;
return;
}
if (work_queue->m_actions.empty()) {
- --work_queue->running_workers;
if (state == State::Running || work_queue->running_workers > 0) {
work_queue->m_cv.wait(lck);
continue;
@@ -162,9 +159,11 @@ namespace vcpkg {
Action action = std::move(work_queue->m_actions.back());
work_queue->m_actions.pop_back();
+ ++work_queue->running_workers;
lck.unlock();
- detail::call_action(action, *work_queue, tld);
+ detail::call_moved_action(action, *work_queue, tld);
lck.lock();
+ --work_queue->running_workers;
}
}
};