[Spice-commits] server/display-channel.cpp server/reds.cpp server/stream-channel.cpp

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun May 23 09:04:36 UTC 2021


 server/display-channel.cpp |   14 +++++++-------
 server/reds.cpp            |   16 ++++++----------
 server/stream-channel.cpp  |    7 ++-----
 3 files changed, 15 insertions(+), 22 deletions(-)

New commits:
commit 51092046f77a775772bb4314d13092247371851b
Author: Rosen Penev <rosenp at gmail.com>
Date:   Sat May 8 14:42:13 2021 -0700

    Remove several usages of SPICE_N_ELEMENTS
    
    It's simpler to just use a for range loop.
    
    Signed-off-by: Rosen Penev <rosenp at gmail.com>
    Acked-by: Frediano Ziglio <freddy77 at gmail.com>

diff --git a/server/display-channel.cpp b/server/display-channel.cpp
index 30d025eb..1d1e71e2 100644
--- a/server/display-channel.cpp
+++ b/server/display-channel.cpp
@@ -2419,10 +2419,9 @@ void display_channel_debug_oom(DisplayChannel *display, const char *msg)
 
 static void guest_set_client_capabilities(DisplayChannel *display)
 {
-    int i;
     RedChannelClient *rcc;
     uint8_t caps[SPICE_CAPABILITIES_SIZE] = { 0 };
-    int caps_available[] = {
+    const int caps_available[] = {
         SPICE_DISPLAY_CAP_SIZED_STREAM,
         SPICE_DISPLAY_CAP_MONITORS_CONFIG,
         SPICE_DISPLAY_CAP_COMPOSITE,
@@ -2446,13 +2445,14 @@ static void guest_set_client_capabilities(DisplayChannel *display)
         red_qxl_set_client_capabilities(display->priv->qxl, FALSE, caps);
     } else {
         // Take least common denominator
-        for (i = 0 ; i < SPICE_N_ELEMENTS(caps_available); ++i) {
-            SET_CAP(caps, caps_available[i]);
+        for (auto &&cap : caps_available) {
+            SET_CAP(caps, cap);
         }
         FOREACH_CLIENT(display, rcc) {
-            for (i = 0 ; i < SPICE_N_ELEMENTS(caps_available); ++i) {
-                if (!rcc->test_remote_cap(caps_available[i]))
-                    CLEAR_CAP(caps, caps_available[i]);
+            for (auto &&cap : caps_available) {
+                if (!rcc->test_remote_cap(cap)) {
+                    CLEAR_CAP(caps, cap);
+                }
             }
         }
         red_qxl_set_client_capabilities(display->priv->qxl, TRUE, caps);
diff --git a/server/reds.cpp b/server/reds.cpp
index c2909a9e..3aecbdb1 100644
--- a/server/reds.cpp
+++ b/server/reds.cpp
@@ -349,25 +349,21 @@ int reds_get_free_channel_id(RedsState *reds, uint32_t type)
     // this mark if some IDs are used.
     // The size of the array limits the possible id returned but
     // usually the IDs used for a channel type are not much.
-    bool used_ids[256];
-
-    unsigned n;
+    std::array<bool, 256> used_ids{};
 
     // mark id used for the specific channel type
-    memset(used_ids, 0, sizeof(used_ids));
     for (const auto &channel: reds->channels) {
-        if (channel->type() == type && channel->id() < SPICE_N_ELEMENTS(used_ids)) {
+        if (channel->type() == type && channel->id() < used_ids.size()) {
             used_ids[channel->id()] = true;
         }
     }
 
     // find first ID not marked as used
-    for (n = 0; n < SPICE_N_ELEMENTS(used_ids); ++n) {
-        if (!used_ids[n]) {
-            return n;
-        }
+    auto it = std::find(used_ids.begin(), used_ids.end(), false);
+    if (it == used_ids.end()) {
+        return -1;
     }
-    return -1;
+    return std::distance(used_ids.begin(), it);
 }
 
 static void reds_mig_cleanup(RedsState *reds)
diff --git a/server/stream-channel.cpp b/server/stream-channel.cpp
index 4d531eba..bc270b0c 100644
--- a/server/stream-channel.cpp
+++ b/server/stream-channel.cpp
@@ -302,11 +302,8 @@ stream_channel_get_supported_codecs(StreamChannel *channel, uint8_t *out_codecs)
         SPICE_DISPLAY_CAP_CODEC_H265,
     };
 
-    bool supported[SPICE_N_ELEMENTS(codec2cap)];
-
-    for (codec = 0; codec < SPICE_N_ELEMENTS(codec2cap); ++codec) {
-        supported[codec] = true;
-    }
+    std::array<bool, SPICE_N_ELEMENTS(codec2cap)> supported;
+    supported.fill(true);
 
     FOREACH_CLIENT(channel, rcc) {
         for (codec = 1; codec < SPICE_N_ELEMENTS(codec2cap); ++codec) {


More information about the Spice-commits mailing list