[go-wiki.wiki] push by - Edited wiki page SliceTricks through web user interface. on 2014-11-20 00:47 GMT

0 views
Skip to first unread message

go-...@googlecode.com

unread,
Nov 19, 2014, 7:48:06 PM11/19/14
to go-...@googlegroups.com
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)
+ }
+}
+}}}
Reply all
Reply to author
Forward
0 new messages