gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated: pq: simplify logic for array query type


From: gnunet
Subject: [gnunet] branch master updated: pq: simplify logic for array query type conversion
Date: Sun, 14 May 2023 17:58:52 +0200

This is an automated email from the git hooks/post-receive script.

oec pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 9135ab24b pq: simplify logic for array query type conversion
9135ab24b is described below

commit 9135ab24b8975742b0a247dc5f1b43c0708ce60d
Author: Özgür Kesim <oec-taler@kesim.org>
AuthorDate: Sun May 14 17:58:18 2023 +0200

    pq: simplify logic for array query type conversion
---
 src/pq/pq_query_helper.c | 122 +++++++++++++++++++++++------------------------
 1 file changed, 61 insertions(+), 61 deletions(-)

diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
index b2bbe8ad4..1f13270c3 100644
--- a/src/pq/pq_query_helper.c
+++ b/src/pq/pq_query_helper.c
@@ -807,7 +807,7 @@ qconv_array (
       case array_of_bool:
         {
           GNUNET_assert (sizeof(bool) == sz);
-          GNUNET_memcpy (out, in, sz);
+          *(bool *) out = (*(bool *) in);
           in  += sz;
           break;
         }
@@ -833,6 +833,7 @@ qconv_array (
           break;
         }
       case array_of_byte:
+      case array_of_string:
         {
           const void *ptr;
 
@@ -840,81 +841,80 @@ qconv_array (
           {
             ptr = in;
             in += sz;
+            if (array_of_string == meta->typ)
+              in += 1;    /* NULL-byte */
           }
           else
             ptr = ((const void **) data)[i];
 
-          GNUNET_memcpy (out, ptr, sz);
-          break;
-        }
-      case array_of_string:
-        {
-          const void *ptr;
-          if (meta->continuous)
-          {
-            ptr = in;
-            in += sz + 1;
-          }
-          else
-            ptr = ((const char **) data)[i];
-
           GNUNET_memcpy (out, ptr, sz);
           break;
         }
       case array_of_abs_time:
-        {
-          const struct GNUNET_TIME_Absolute *abs;
-
-          if (meta->continuous)
-          {
-            abs = (const struct GNUNET_TIME_Absolute *) in;
-            in += sz;
-          }
-          else
-            abs = ((const struct GNUNET_TIME_Absolute **) data)[i];
-
-          if (abs->abs_value_us > INT64_MAX)
-            *(uint64_t *) out = GNUNET_htonll (INT64_MAX);
-          else
-            *(uint64_t *) out = GNUNET_htonll (abs->abs_value_us);
-
-          break;
-        }
       case array_of_rel_time:
-        {
-          const struct GNUNET_TIME_Relative *rel;
-
-          if (meta->continuous)
-          {
-            rel = (const struct GNUNET_TIME_Relative *) in;
-            in += sz;
-          }
-          else
-            rel = ((const struct GNUNET_TIME_Relative **) data)[i];
-
-          if (rel->rel_value_us > INT64_MAX)
-            *(uint64_t *) out = GNUNET_htonll (INT64_MAX);
-          else
-            *(uint64_t *) out = GNUNET_htonll (rel->rel_value_us);
-
-          break;
-        }
       case array_of_timestamp:
         {
-          const struct GNUNET_TIME_Timestamp *ts;
+          uint64_t val;
 
-          if (meta->continuous)
+          switch (meta->typ)
           {
-            ts = (const struct GNUNET_TIME_Timestamp *) in;
-            in += sz;
+          case array_of_abs_time:
+            {
+              const struct GNUNET_TIME_Absolute *abs;
+
+              if (meta->continuous)
+              {
+                abs = (const struct GNUNET_TIME_Absolute *) in;
+                in += sz;
+              }
+              else
+                abs = ((const struct GNUNET_TIME_Absolute **) data)[i];
+
+              val = abs->abs_value_us;
+              break;
+            }
+          case array_of_rel_time:
+            {
+              const struct GNUNET_TIME_Relative *rel;
+
+              if (meta->continuous)
+              {
+                rel = (const struct GNUNET_TIME_Relative *) in;
+                in += sz;
+              }
+              else
+                rel = ((const struct GNUNET_TIME_Relative **) data)[i];
+
+              val = rel->rel_value_us;
+
+              break;
+            }
+          case array_of_timestamp:
+            {
+              const struct GNUNET_TIME_Timestamp *ts;
+
+              if (meta->continuous)
+              {
+                ts = (const struct GNUNET_TIME_Timestamp *) in;
+                in += sz;
+              }
+              else
+                ts = ((const struct GNUNET_TIME_Timestamp **) data)[i];
+
+              val = ts->abs_time.abs_value_us;
+
+              break;
+            }
+          default:
+            {
+              GNUNET_assert (0);
+            }
           }
-          else
-            ts = ((const struct GNUNET_TIME_Timestamp **) data)[i];
 
-          if (ts->abs_time.abs_value_us > INT64_MAX)
-            *(uint64_t *) out = GNUNET_htonll (INT64_MAX);
-          else
-            *(uint64_t *) out = GNUNET_htonll (ts->abs_time.abs_value_us);
+          if (val > INT64_MAX)
+            val = INT64_MAX;
+
+          *(uint64_t *) out = GNUNET_htonll (val);
 
           break;
         }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]