mem: Use a const T & in write<> to avoid an unnecessary copy.
authorGabe Black <gabeblack@google.com>
Thu, 2 May 2019 03:16:56 +0000 (20:16 -0700)
committerGabe Black <gabeblack@google.com>
Wed, 29 May 2019 04:23:55 +0000 (04:23 +0000)
If the type T is complex/large, the it makes sense to access it in place
and not copy it and then not modify it.

Change-Id: Idd24be4fbba636375637ff72b1ba5ee32eb76215
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18573
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>

src/mem/port_proxy.hh

index 096f82664a884120558b1db305270dbe8aef9066..469273f85f59e78714577c85ca7470c5d5c73ae7 100644 (file)
@@ -195,7 +195,7 @@ class PortProxy
      * Write object T to address. Writes sizeof(T) bytes.
      */
     template <typename T>
-    void write(Addr address, data) const;
+    void write(Addr address, const T &data) const;
 
     /**
      * Read sizeof(T) bytes from address and return as object T.
@@ -256,7 +256,7 @@ PortProxy::read(Addr address) const
 
 template <typename T>
 void
-PortProxy::write(Addr address, data) const
+PortProxy::write(Addr address, const T &data) const
 {
     writeBlob(address, &data, sizeof(T));
 }