Skip to content

Commit

Permalink
add blurb about += vs <<
Browse files Browse the repository at this point in the history
git-svn-id: https://www.metasploit.com/svn/framework3/trunk@9745 4d416f70-5f16-0410-b530-b9f4589650da
  • Loading branch information
jduck committed Jul 9, 2010
1 parent a1d0c40 commit 43db7b0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions HACKING
Expand Up @@ -52,6 +52,23 @@ which always returns a String. If you need the ASCII byte, unpack it like
so:
str[idx,1].unpack("C")

6. Whenever possible, avoid using '+' or '+=' to concatenate strings.
The '<<' operator is significantly faster. The difference will become
even more apparent when doing string manipulation in a loop. The
following table approximates the underlying implementation:
Ruby Pseudo-C
----------- ----------------
a = b + c a = malloc(b.len+c.len+1);
strcpy(a, b);
memcpy(a+b.len, c, c.len);
a[b.len + c.len] = '\0';
a = b a = b;
a << c a = realloc(a, a.len+c.len+1);
memcpy(a+a.len, c, c.len);
a[a.len + c.len] = '\0';
Note that the original value of 'b' is lost in the second case. Care
must be taken to duplicate strings that you do not want to modify.


Creating New Modules
====================
Expand Down

0 comments on commit 43db7b0

Please sign in to comment.