Revision: 32f5f21b33f5
Branch: default
Author:
kamil....@gmail.com
Date: Thu Nov 20 00:47:54 2014 UTC
Log: Edited wiki page SliceTricks through web user interface.
https://code.google.com/p/go-wiki/source/detail?r=32f5f21b33f5&repo=wiki
Modified:
/SliceTricks.wiki
=======================================
--- /SliceTricks.wiki Tue May 20 02:57:16 2014 UTC
+++ /SliceTricks.wiki Thu Nov 20 00:47:54 2014 UTC
@@ -83,3 +83,17 @@
{{{
a = append(a, x)
}}}
+
+== Additional Tricks ==
+=== Filtering without allocating ===
+
+This trick uses the fact that a slice shares the same backing array and
capacity as the original, so the storage is reused for the filtered slice.
Of course, the original contents are modified.
+
+{{{
+b := a[:0]
+for _, x := range a {
+ if f(x) {
+ b = append(b, x)
+ }
+}
+}}}