diff --git a/modcc/cprinter.cpp b/modcc/cprinter.cpp
index c588c5ec2af70a59a34c79384f2b9cf23895a980..f4c9de899782ae0f9fca2aa5e4ac9f406669759b 100644
--- a/modcc/cprinter.cpp
+++ b/modcc/cprinter.cpp
@@ -136,7 +136,12 @@ CPrinter::CPrinter(Module &m, bool o)
     if (m.kind() == moduleKind::density) {
         text_.add_line("// add the user-supplied weights for converting from current density");
         text_.add_line("// to per-compartment current in nA");
-        text_.add_line("memory::copy(weights, weights_(0, size()));");
+        if(optimize_) {
+            text_.add_line("memory::copy(weights, view(weights_, size()));");
+        }
+        else {
+            text_.add_line("memory::copy(weights, weights_(0, size()));");
+        }
         text_.add_line();
     }