summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRosen Penev <rosenp@gmail.com>2021-05-08 15:14:58 -0700
committerFrediano Ziglio <freddy77@gmail.com>2021-05-31 08:08:26 +0100
commit115260e4e5e57cc16ef56aaca76028a620415605 (patch)
treeb30aec0e502ace5eef55fd91cda52bdd5e2e9660
parent3de587a76c165262dea9af30c0fbe9bcbbde9cf4 (diff)
Manual algorithm changes
Signed-off-by: Rosen Penev <rosenp@gmail.com> Acked-by: Frediano Ziglio <freddy77@gmail.com>
-rw-r--r--server/dispatcher.cpp4
-rw-r--r--server/display-channel.cpp4
-rw-r--r--server/reds.cpp27
-rw-r--r--server/video-stream.cpp9
4 files changed, 18 insertions, 26 deletions
diff --git a/server/dispatcher.cpp b/server/dispatcher.cpp
index fa2afcb5..6973cc09 100644
--- a/server/dispatcher.cpp
+++ b/server/dispatcher.cpp
@@ -106,7 +106,7 @@ static int read_safe(int fd, void *raw_buf, size_t size, bool block)
{
int read_size = 0;
int ret;
- uint8_t *buf = reinterpret_cast<uint8_t *>(raw_buf);
+ auto buf = reinterpret_cast<uint8_t *>(raw_buf);
if (size == 0) {
return 0;
@@ -172,7 +172,7 @@ static int write_safe(int fd, const void *raw_buf, size_t size)
{
int written_size = 0;
int ret;
- const uint8_t *buf = reinterpret_cast<const uint8_t *>(raw_buf);
+ auto buf = reinterpret_cast<const uint8_t *>(raw_buf);
while (written_size < size) {
ret = socket_write(fd, buf + written_size, size - written_size);
diff --git a/server/display-channel.cpp b/server/display-channel.cpp
index 9eac7463..053ec34f 100644
--- a/server/display-channel.cpp
+++ b/server/display-channel.cpp
@@ -44,8 +44,8 @@ DisplayChannel::~DisplayChannel()
spice_assert(count == NUM_STREAMS);
spice_assert(ring_is_empty(&priv->streams));
- for (count = 0; count < NUM_SURFACES; ++count) {
- spice_assert(priv->surfaces[count].context.canvas == nullptr);
+ for (const auto &surface : priv->surfaces) {
+ spice_assert(surface.context.canvas == nullptr);
}
}
diff --git a/server/reds.cpp b/server/reds.cpp
index 1bf62fc7..3fd6553a 100644
--- a/server/reds.cpp
+++ b/server/reds.cpp
@@ -593,14 +593,12 @@ gboolean reds_config_get_agent_mouse(const RedsState *reds)
static void reds_update_mouse_mode(RedsState *reds)
{
int allowed = 0;
- int qxl_count = reds->qxl_instances.size();
- int display_channel_count = 0;
-
- for (const auto &channel: reds->channels) {
- if (channel->type() == SPICE_CHANNEL_DISPLAY) {
- ++display_channel_count;
- }
- }
+ auto qxl_count = reds->qxl_instances.size();
+ auto display_channel_count =
+ std::count_if(reds->channels.begin(), reds->channels.end(),
+ [](const red::shared_ptr<RedChannel> &channel) {
+ return channel->type() == SPICE_CHANNEL_DISPLAY;
+ });
if ((reds->config->agent_mouse && reds->vdagent) ||
(reds->inputs_channel && reds->inputs_channel->has_tablet() &&
@@ -3711,9 +3709,7 @@ SPICE_GNUC_VISIBLE void spice_server_destroy(SpiceServer *reds)
servers = g_list_remove(servers, reds);
pthread_mutex_unlock(&global_reds_lock);
- for (auto qxl: reds->qxl_instances) {
- red_qxl_destroy(qxl);
- }
+ std::for_each(reds->qxl_instances.begin(), reds->qxl_instances.end(), red_qxl_destroy);
if (reds->inputs_channel) {
reds->inputs_channel->destroy();
@@ -4336,11 +4332,10 @@ static gboolean reds_use_client_monitors_config(RedsState *reds)
return FALSE;
}
- FOREACH_QXL_INSTANCE(reds, qxl) {
- if (!red_qxl_client_monitors_config(qxl, nullptr))
- return FALSE;
- }
- return TRUE;
+ return std::all_of(reds->qxl_instances.begin(), reds->qxl_instances.end(),
+ [](QXLInstance *qxl) {
+ return red_qxl_client_monitors_config(qxl, nullptr);
+ });
}
static void reds_client_monitors_config(RedsState *reds, VDAgentMonitorsConfig *monitors_config)
diff --git a/server/video-stream.cpp b/server/video-stream.cpp
index fadeda8f..162bb25d 100644
--- a/server/video-stream.cpp
+++ b/server/video-stream.cpp
@@ -129,14 +129,11 @@ static void video_stream_free(DisplayChannel *display, VideoStream *stream)
void display_channel_init_video_streams(DisplayChannel *display)
{
- int i;
-
ring_init(&display->priv->streams);
display->priv->free_streams = nullptr;
- for (i = 0; i < NUM_STREAMS; i++) {
- VideoStream *stream = display_channel_get_nth_video_stream(display, i);
- ring_item_init(&stream->link);
- video_stream_free(display, stream);
+ for (auto &&stream : display->priv->streams_buf) {
+ ring_item_init(&stream.link);
+ video_stream_free(display, &stream);
}
}