Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Avoid a redundant allocation in cfstr_to_str

  • Loading branch information...
commit bd1a5e8110bb4030e2777cf3c7c0135fce623075 1 parent 161ed66
@ferrous26 ferrous26 authored
Showing with 2 additions and 5 deletions.
  1. +2 −5 ext/xcodeproj/xcodeproj_ext.c
View
7 ext/xcodeproj/xcodeproj_ext.c
@@ -21,13 +21,10 @@ static VALUE
cfstr_to_str(const void *cfstr) {
CFDataRef data = CFStringCreateExternalRepresentation(NULL, cfstr, kCFStringEncodingUTF8, 0);
assert(data != NULL);
- long len = (long)CFDataGetLength(data);
- char *buf = (char *)malloc(len+1);
- assert(buf != NULL);
- CFDataGetBytes(data, CFRangeMake(0, len), buf);
+ long len = (long)CFDataGetLength(data);
+ char *buf = (char *)CFDataGetBytePtr(data);
register VALUE str = rb_str_new(buf, len);
- free(buf);
// force UTF-8 encoding in Ruby 1.9+
ID forceEncodingId = rb_intern("force_encoding");
Please sign in to comment.
Something went wrong with that request. Please try again.