Differences From Artifact [435afd59fe]:
- File src/OFHTTPRequest.m — part of check-in [7008aeed34] at 2012-07-31 11:27:26 on branch trunk — OFHTTPRequest: Use OFUnsupportedVersionException. (user: js, size: 12701) [annotate] [blame] [check-ins using]
To Artifact [c7bd138f6a]:
- File
src/OFHTTPRequest.m
— part of check-in
[1255f3a11a]
at
2012-08-10 20:08:24
on branch trunk
— Directly use the runtime's autorelease pools.
This greatly improves performance, as it gets rid of the overhead of
OFAutoreleasePool. (user: js, size: 12782) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
23 24 25 26 27 28 29 | #import "OFHTTPRequest.h" #import "OFString.h" #import "OFURL.h" #import "OFTCPSocket.h" #import "OFDictionary.h" #import "OFDataArray.h" | < > | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #import "OFHTTPRequest.h" #import "OFString.h" #import "OFURL.h" #import "OFTCPSocket.h" #import "OFDictionary.h" #import "OFDataArray.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerReplyException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" #import "OFUnsupportedVersionException.h" #import "autorelease.h" #import "macros.h" Class of_http_request_tls_socket_class = Nil; static OF_INLINE void normalizeKey(OFString *key) { |
︙ | ︙ | |||
183 184 185 186 187 188 189 | - (OFHTTPRequestResult*)perform { return [self performWithRedirects: 10]; } - (OFHTTPRequestResult*)performWithRedirects: (size_t)redirects { | | | 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | - (OFHTTPRequestResult*)perform { return [self performWithRedirects: 10]; } - (OFHTTPRequestResult*)performWithRedirects: (size_t)redirects { void *pool = objc_autoreleasePoolPush(); OFString *scheme = [URL scheme]; OFTCPSocket *sock; OFHTTPRequestResult *result; OFString *line, *path, *version; OFMutableDictionary *serverHeaders; OFDataArray *data; OFEnumerator *keyEnumerator, *objectEnumerator; |
︙ | ︙ | |||
363 364 365 366 367 368 369 | if (status == 303) { requestType = OF_HTTP_REQUEST_TYPE_GET; [queryString release]; queryString = nil; } | | | 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | if (status == 303) { requestType = OF_HTTP_REQUEST_TYPE_GET; [queryString release]; queryString = nil; } objc_autoreleasePoolPop(pool); return [self performWithRedirects: redirects - 1]; } [serverHeaders setObject: value forKey: key]; } |
︙ | ︙ | |||
393 394 395 396 397 398 399 | @throw [OFOutOfRangeException exceptionWithClass: [self class]]; } buffer = [self allocMemoryWithSize: of_pagesize]; bytesReceived = 0; @try { | < < > | 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | @throw [OFOutOfRangeException exceptionWithClass: [self class]]; } buffer = [self allocMemoryWithSize: of_pagesize]; bytesReceived = 0; @try { if (chunked) { for (;;) { void *pool2 = objc_autoreleasePoolPush(); size_t pos, toRead; @try { line = [sock readLine]; } @catch (OFInvalidEncodingException *e) { @throw [OFInvalidServerReplyException exceptionWithClass: [self class]]; |
︙ | ︙ | |||
435 436 437 438 439 440 441 | length = [sock readIntoBuffer: buffer length: length]; [delegate request: self didReceiveData: buffer withLength: length]; | | > > | > > | > < < | 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | length = [sock readIntoBuffer: buffer length: length]; [delegate request: self didReceiveData: buffer withLength: length]; objc_autoreleasePoolPop(pool2); pool2 = objc_autoreleasePoolPush(); bytesReceived += length; [data addItemsFromCArray: buffer count: length]; toRead -= length; } @try { line = [sock readLine]; } @catch (OFInvalidEncodingException *e) { @throw [OFInvalidServerReplyException exceptionWithClass: [self class]]; } if (![line isEqual: @""]) @throw [OFInvalidServerReplyException exceptionWithClass: [self class]]; objc_autoreleasePoolPop(pool2); } } else { size_t length; while ((length = [sock readIntoBuffer: buffer length: of_pagesize]) > 0) { void *pool2 = objc_autoreleasePoolPush(); [delegate request: self didReceiveData: buffer withLength: length]; objc_autoreleasePoolPop(pool2); bytesReceived += length; [data addItemsFromCArray: buffer count: length]; if (contentLengthHeader != nil && bytesReceived >= contentLength) break; } } } @finally { [self freeMemory: buffer]; } [sock close]; /* |
︙ | ︙ | |||
516 517 518 519 520 521 522 | [result release]; @throw [OFHTTPRequestFailedException exceptionWithClass: [self class] HTTPRequest: self result: result]; } | | | 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | [result release]; @throw [OFHTTPRequestFailedException exceptionWithClass: [self class] HTTPRequest: self result: result]; } objc_autoreleasePoolPop(pool); return [result autorelease]; } @end @implementation OFHTTPRequestResult - initWithStatusCode: (short)status |
︙ | ︙ |