[Spice-devel] [PATCH] constify some variable

Frediano Ziglio fziglio at redhat.com
Fri Aug 21 02:52:51 PDT 2015


Although minor change allows the compiler to do some possible code
optimization.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/main_channel.c   |  4 ++--
 server/red_channel.c    |  6 +++---
 server/red_dispatcher.c |  8 ++++----
 server/red_worker.c     | 36 ++++++++++++++++++------------------
 4 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/server/main_channel.c b/server/main_channel.c
index 0ecc9df..e18d0bf 100644
--- a/server/main_channel.c
+++ b/server/main_channel.c
@@ -57,7 +57,7 @@
 
 #define CLIENT_CONNECTIVITY_TIMEOUT (30*1000) // 30 seconds
 
-static uint8_t zero_page[ZERO_BUF_SIZE] = {0};
+static const uint8_t zero_page[ZERO_BUF_SIZE] = {0};
 
 enum {
     PIPE_ITEM_TYPE_MAIN_CHANNELS_LIST = PIPE_ITEM_TYPE_CHANNEL_BASE,
@@ -384,7 +384,7 @@ static void main_channel_marshall_ping(RedChannelClient *rcc,
     while (size_left > 0) {
         int now = MIN(ZERO_BUF_SIZE, size_left);
         size_left -= now;
-        spice_marshaller_add_ref(m, zero_page, now);
+        spice_marshaller_add_ref(m, (uint8_t *) zero_page, now);
     }
 }
 
diff --git a/server/red_channel.c b/server/red_channel.c
index 3f40fab..2b21714 100644
--- a/server/red_channel.c
+++ b/server/red_channel.c
@@ -179,7 +179,7 @@ static void mini_header_set_msg_sub_list(SpiceDataHeaderOpaque *header, uint32_t
     spice_error("attempt to set header sub list on mini header");
 }
 
-static SpiceDataHeaderOpaque full_header_wrapper = {NULL, sizeof(SpiceDataHeader),
+static const SpiceDataHeaderOpaque full_header_wrapper = {NULL, sizeof(SpiceDataHeader),
                                                     full_header_set_msg_type,
                                                     full_header_set_msg_size,
                                                     full_header_set_msg_serial,
@@ -187,7 +187,7 @@ static SpiceDataHeaderOpaque full_header_wrapper = {NULL, sizeof(SpiceDataHeader
                                                     full_header_get_msg_type,
                                                     full_header_get_msg_size};
 
-static SpiceDataHeaderOpaque mini_header_wrapper = {NULL, sizeof(SpiceMiniDataHeader),
+static const SpiceDataHeaderOpaque mini_header_wrapper = {NULL, sizeof(SpiceMiniDataHeader),
                                                     mini_header_set_msg_type,
                                                     mini_header_set_msg_size,
                                                     mini_header_set_msg_serial,
@@ -1089,7 +1089,7 @@ static void dummy_watch_remove(SpiceWatch *watch)
 }
 
 // TODO: actually, since I also use channel_client_dummym, no need for core. Can be NULL
-SpiceCoreInterface dummy_core = {
+const SpiceCoreInterface dummy_core = {
     .watch_update_mask = dummy_watch_update_mask,
     .watch_add = dummy_watch_add,
     .watch_remove = dummy_watch_remove,
diff --git a/server/red_dispatcher.c b/server/red_dispatcher.c
index 113848a..e796411 100644
--- a/server/red_dispatcher.c
+++ b/server/red_dispatcher.c
@@ -210,7 +210,7 @@ typedef struct RendererInfo {
     const char *name;
 } RendererInfo;
 
-static RendererInfo renderers_info[] = {
+static const RendererInfo renderers_info[] = {
     {RED_RENDERER_SW, "sw"},
 #ifdef USE_OPENGL
     {RED_RENDERER_OGL_PBUF, "oglpbuf"},
@@ -222,9 +222,9 @@ static RendererInfo renderers_info[] = {
 static uint32_t renderers[RED_MAX_RENDERERS];
 static uint32_t num_renderers = 0;
 
-static RendererInfo *find_renderer(const char *name)
+static const RendererInfo *find_renderer(const char *name)
 {
-    RendererInfo *inf = renderers_info;
+    const RendererInfo *inf = renderers_info;
     while (inf->name) {
         if (strcmp(name, inf->name) == 0) {
             return inf;
@@ -236,7 +236,7 @@ static RendererInfo *find_renderer(const char *name)
 
 int red_dispatcher_add_renderer(const char *name)
 {
-    RendererInfo *inf;
+    const RendererInfo *inf;
 
     if (num_renderers == RED_MAX_RENDERERS || !(inf = find_renderer(name))) {
         return FALSE;
diff --git a/server/red_worker.c b/server/red_worker.c
index cd7fea4..ccba8a3 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -1077,7 +1077,7 @@ static void red_display_release_stream_clip(RedWorker *worker, StreamClipItem *i
 static int red_display_free_some_independent_glz_drawables(DisplayChannelClient *dcc);
 static void red_display_free_glz_drawable(DisplayChannelClient *dcc, RedGlzDrawable *drawable);
 static ImageItem *red_add_surface_area_image(DisplayChannelClient *dcc, int surface_id,
-                                             SpiceRect *area, PipeItem *pos, int can_lossy);
+                                             const SpiceRect *area, PipeItem *pos, int can_lossy);
 static BitmapGradualType _get_bitmap_graduality_level(RedWorker *worker, SpiceBitmap *bitmap,
                                                       uint32_t group_id);
 static inline int _stride_is_extra(SpiceBitmap *bitmap);
@@ -5174,7 +5174,7 @@ static void red_current_flush(RedWorker *worker, int surface_id)
 
 // adding the pipe item after pos. If pos == NULL, adding to head.
 static ImageItem *red_add_surface_area_image(DisplayChannelClient *dcc, int surface_id,
-                                             SpiceRect *area, PipeItem *pos, int can_lossy)
+                                             const SpiceRect *area, PipeItem *pos, int can_lossy)
 {
     DisplayChannel *display_channel = DCC_TO_DC(dcc);
     RedWorker *worker = display_channel->common.worker;
@@ -7073,8 +7073,8 @@ static void surface_lossy_region_update(RedWorker *worker, DisplayChannelClient
     }
 }
 
-static inline int drawable_intersects_with_areas(Drawable *drawable, int surface_ids[],
-                                                 SpiceRect *surface_areas[],
+static inline int drawable_intersects_with_areas(Drawable *drawable, const int surface_ids[],
+                                                 const SpiceRect *surface_areas[],
                                                  int num_surfaces)
 {
     int i;
@@ -7148,8 +7148,8 @@ static inline int drawable_depends_on_areas(Drawable *drawable,
 
 static int pipe_rendered_drawables_intersect_with_areas(RedWorker *worker,
                                                         DisplayChannelClient *dcc,
-                                                        int surface_ids[],
-                                                        SpiceRect *surface_areas[],
+                                                        const int surface_ids[],
+                                                        const SpiceRect *surface_areas[],
                                                         int num_surfaces)
 {
     PipeItem *pipe_item;
@@ -7238,8 +7238,8 @@ static void red_pipe_replace_rendered_drawables_with_images(RedWorker *worker,
 static void red_add_lossless_drawable_dependencies(RedWorker *worker,
                                                    RedChannelClient *rcc,
                                                    Drawable *item,
-                                                   int deps_surfaces_ids[],
-                                                   SpiceRect *deps_areas[],
+                                                   const int deps_surfaces_ids[],
+                                                   const SpiceRect *deps_areas[],
                                                    int num_deps)
 {
     RedDrawable *drawable = item->red_drawable;
@@ -7285,7 +7285,7 @@ static void red_add_lossless_drawable_dependencies(RedWorker *worker,
         }
     } else {
         int drawable_surface_id[1];
-        SpiceRect *drawable_bbox[1];
+        const SpiceRect *drawable_bbox[1];
 
         drawable_surface_id[0] = drawable->surface_id;
         drawable_bbox[0] = &drawable->bbox;
@@ -7371,7 +7371,7 @@ static void red_lossy_marshall_qxl_draw_fill(RedWorker *worker,
         surface_lossy_region_update(worker, dcc, item, has_mask, FALSE);
     } else {
         int resend_surface_ids[2];
-        SpiceRect *resend_areas[2];
+        const SpiceRect *resend_areas[2];
         int num_resend = 0;
 
         if (dest_is_lossy) {
@@ -7471,7 +7471,7 @@ static void red_lossy_marshall_qxl_draw_opaque(RedWorker *worker,
         surface_lossy_region_update(worker, dcc, item, has_mask, src_is_lossy);
     } else {
         int resend_surface_ids[2];
-        SpiceRect *resend_areas[2];
+        const SpiceRect *resend_areas[2];
         int num_resend = 0;
 
         if (src_is_lossy && (src_bitmap_data.type == BITMAP_DATA_TYPE_SURFACE)) {
@@ -7583,7 +7583,7 @@ static void red_lossy_marshall_qxl_draw_transparent(RedWorker *worker,
         // don't update surface lossy region since transperent areas might be lossy
     } else {
         int resend_surface_ids[1];
-        SpiceRect *resend_areas[1];
+        const SpiceRect *resend_areas[1];
 
         resend_surface_ids[0] = src_bitmap_data.id;
         resend_areas[0] = &src_bitmap_data.lossy_rect;
@@ -7742,7 +7742,7 @@ static void red_lossy_marshall_qxl_draw_blend(RedWorker *worker,
         red_marshall_qxl_draw_blend(worker, rcc, base_marshaller, dpi);
     } else {
         int resend_surface_ids[2];
-        SpiceRect *resend_areas[2];
+        const SpiceRect *resend_areas[2];
         int num_resend = 0;
 
         if (src_is_lossy && (src_bitmap_data.type == BITMAP_DATA_TYPE_SURFACE)) {
@@ -7922,7 +7922,7 @@ static void red_lossy_marshall_qxl_draw_rop3(RedWorker *worker,
         surface_lossy_region_update(worker, dcc, item, has_mask, FALSE);
     } else {
         int resend_surface_ids[3];
-        SpiceRect *resend_areas[3];
+        const SpiceRect *resend_areas[3];
         int num_resend = 0;
 
         if (src_is_lossy && (src_bitmap_data.type == BITMAP_DATA_TYPE_SURFACE)) {
@@ -8005,7 +8005,7 @@ static void red_lossy_marshall_qxl_draw_composite(RedWorker *worker,
     }
     else {
         int resend_surface_ids[3];
-        SpiceRect *resend_areas[3];
+        const SpiceRect *resend_areas[3];
         int num_resend = 0;
 
         if (src_is_lossy && (src_bitmap_data.type == BITMAP_DATA_TYPE_SURFACE)) {
@@ -8092,7 +8092,7 @@ static void red_lossy_marshall_qxl_draw_stroke(RedWorker *worker,
         red_marshall_qxl_draw_stroke(worker, rcc, base_marshaller, dpi);
     } else {
         int resend_surface_ids[2];
-        SpiceRect *resend_areas[2];
+        const SpiceRect *resend_areas[2];
         int num_resend = 0;
 
         if (brush_is_lossy && (brush_bitmap_data.type == BITMAP_DATA_TYPE_SURFACE)) {
@@ -8184,7 +8184,7 @@ static void red_lossy_marshall_qxl_draw_text(RedWorker *worker,
         red_marshall_qxl_draw_text(worker, rcc, base_marshaller, dpi);
     } else {
         int resend_surface_ids[3];
-        SpiceRect *resend_areas[3];
+        const SpiceRect *resend_areas[3];
         int num_resend = 0;
 
         if (fg_is_lossy && (fg_bitmap_data.type == BITMAP_DATA_TYPE_SURFACE)) {
@@ -10423,7 +10423,7 @@ static void worker_watch_remove(SpiceWatch *watch)
     memset(watch, 0, sizeof(SpiceWatch));
 }
 
-SpiceCoreInterface worker_core = {
+static const SpiceCoreInterface worker_core = {
     .timer_add = spice_timer_queue_add,
     .timer_start = spice_timer_set,
     .timer_cancel = spice_timer_cancel,
-- 
2.4.3



More information about the Spice-devel mailing list