diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-10-16 16:14:55 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-10-26 15:54:27 +0100 |
commit | 5173bf1bb8d21054b0dd6251d23eb37323d6c525 (patch) | |
tree | d13536c22b8279e9fd7e8f4892596c42973170f3 /platform/darwin | |
parent | 4e3503ea6cf30c55a2cc86f78c4a607bd14f1c41 (diff) | |
download | qtlocation-mapboxgl-5173bf1bb8d21054b0dd6251d23eb37323d6c525.tar.gz |
[core] Make response data shared to avoid excessive copying
Diffstat (limited to 'platform/darwin')
-rw-r--r-- | platform/darwin/http_request_nsurl.mm | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/platform/darwin/http_request_nsurl.mm b/platform/darwin/http_request_nsurl.mm index f1f6e3fbb9..f5a4d8ef97 100644 --- a/platform/darwin/http_request_nsurl.mm +++ b/platform/darwin/http_request_nsurl.mm @@ -221,6 +221,9 @@ void HTTPNSURLRequest::handleResult(NSData *data, NSURLResponse *res, NSError *e // TODO: Use different codes for host not found, timeout, invalid URL etc. // These can be categorized in temporary and permanent errors. response = std::make_unique<Response>(); + if (data) { + response->data = std::make_shared<std::string>((const char *)[data bytes], [data length]); + } response->status = Response::Error; response->message = [[error localizedDescription] UTF8String]; @@ -253,7 +256,7 @@ void HTTPNSURLRequest::handleResult(NSData *data, NSURLResponse *res, NSError *e const long responseCode = [(NSHTTPURLResponse *)res statusCode]; response = std::make_unique<Response>(); - response->data = {(const char *)[data bytes], [data length]}; + response->data = std::make_shared<std::string>((const char *)[data bytes], [data length]); NSDictionary *headers = [(NSHTTPURLResponse *)res allHeaderFields]; NSString *cache_control = [headers objectForKey:@"Cache-Control"]; |