]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: utime_t encoding optimization
authorXinze Chi <xinze@xsky.com>
Mon, 14 Dec 2015 16:29:14 +0000 (00:29 +0800)
committerXinze Chi <xinze@xsky.com>
Mon, 14 Dec 2015 16:29:14 +0000 (00:29 +0800)
there is no padding between tv_sec and tv_nsec, no matter 32-bit
or 64-bit machine.

Signed-off-by: Xinze Chi <xinze@xsky.com>
src/include/utime.h

index 27241e0b32425c09060ac36d1fc7f4b9ef3d62b1..a60501a63faf6452294a8b26a2f0740a1f9dbb9b 100644 (file)
 // --------
 // utime_t
 
+/* WARNING: If add member in utime_t, please make sure the encode/decode funtion
+ * work well. For little-endian machine, we should make sure there is no padding
+ * in 32-bit machine and 64-bit machine.
+ * You should also modify the padding_check function.
+ */
 class utime_t {
 public:
   struct {
@@ -95,14 +100,29 @@ public:
     tv.tv_sec = v->tv_sec;
     tv.tv_nsec = v->tv_usec*1000;
   }
-
+  void padding_check() {
+    static_assert(
+      sizeof(utime_t) ==
+        sizeof(tv.tv_sec) +
+        sizeof(tv.tv_nsec)
+      ,
+      "utime_t have padding");
+  }
   void encode(bufferlist &bl) const {
+#if defined(CEPH_LITTLE_ENDIAN)
+    bl.append((char *)(this), sizeof(__u32) + sizeof(__u32));
+#else
     ::encode(tv.tv_sec, bl);
     ::encode(tv.tv_nsec, bl);
+#endif
   }
   void decode(bufferlist::iterator &p) {
+#if defined(CEPH_LITTLE_ENDIAN)
+    p.copy(sizeof(__u32) + sizeof(__u32), (char *)(this));
+#else
     ::decode(tv.tv_sec, p);
     ::decode(tv.tv_nsec, p);
+#endif
   }
 
   void encode_timeval(struct ceph_timespec *t) const {