Differences From Artifact [1971d4e07a]:
- File src/OFStream.m — part of check-in [bd923d90c7] at 2011-09-15 10:57:42 on branch trunk — Add -[tryReadTillDelimiter:]. (user: js, size: 26281) [annotate] [blame] [check-ins using]
To Artifact [c69f9cbafe]:
- File
src/OFStream.m
— part of check-in
[295193f0b9]
at
2011-09-16 12:40:23
on branch trunk
— Optimize -[readLine] and -[readTillDelimiter:] a little.
They should be as fast as they were before -[tryReadLine] etc. were
introduced now. (user: js, size: 27024) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
503 504 505 506 507 508 509 | } @finally { [self freeMemory: buffer]; } return ret; } | < < < < < | < < | < < < < < < < < < < < < < | | 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | } @finally { [self freeMemory: buffer]; } return ret; } - (OFString*)_tryReadLineWithEncoding: (of_string_encoding_t)encoding checkCache: (BOOL)checkCache { size_t i, bufferLength, retLength; char *retCString, *buffer, *newCache; OFString *ret; /* Look if there's a line or \0 in our cache */ if (checkCache && cache != NULL) { for (i = 0; i < cacheLength; i++) { if (OF_UNLIKELY(cache[i] == '\n' || cache[i] == '\0')) { retLength = i; if (i > 0 && cache[i - 1] == '\r') retLength--; |
︙ | ︙ | |||
664 665 666 667 668 669 670 | } @finally { [self freeMemory: buffer]; } return nil; } | | < | < | | > > > | | > | | < | > > > > > > | | > | | 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 | } @finally { [self freeMemory: buffer]; } return nil; } - (OFString*)readLine { return [self readLineWithEncoding: OF_STRING_ENCODING_UTF_8]; } - (OFString*)readLineWithEncoding: (of_string_encoding_t)encoding { OFString *line = nil; if ((line = [self _tryReadLineWithEncoding: encoding checkCache: YES]) != nil) return line; while ((line = [self _tryReadLineWithEncoding: encoding checkCache: NO]) == nil) if ([self isAtEndOfStream]) return nil; return line; } - (OFString*)tryReadLine { return [self tryReadLineWithEncoding: OF_STRING_ENCODING_UTF_8]; } - (OFString*)tryReadLineWithEncoding: (of_string_encoding_t)encoding { return [self _tryReadLineWithEncoding: encoding checkCache: YES]; } - (OFString*)_tryReadTillDelimiter: (OFString*)delimiter withEncoding: (of_string_encoding_t)encoding checkCache: (BOOL)checkCache { const char *delimiterUTF8String; size_t i, j, delimiterLength, bufferLength, retLength; char *retCString, *buffer, *newCache; OFString *ret; /* FIXME: Convert delimiter to specified charset */ delimiterUTF8String = [delimiter UTF8String]; delimiterLength = [delimiter UTF8StringLength]; j = 0; if (delimiterLength == 0) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; /* Look if there's something in our cache */ if (checkCache && cache != NULL) { for (i = 0; i < cacheLength; i++) { if (cache[i] != delimiterUTF8String[j++]) j = 0; if (j == delimiterLength || cache[i] == '\0') { if (cache[i] == '\0') delimiterLength = 1; |
︙ | ︙ | |||
826 827 828 829 830 831 832 833 834 835 836 837 838 839 | } @finally { [self freeMemory: buffer]; } return nil; } - (BOOL)buffersWrites { return buffersWrites; } - (void)setBuffersWrites: (BOOL)enable { | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 | } @finally { [self freeMemory: buffer]; } return nil; } - (OFString*)readTillDelimiter: (OFString*)delimiter { return [self readTillDelimiter: delimiter withEncoding: OF_STRING_ENCODING_UTF_8]; } - (OFString*)readTillDelimiter: (OFString*)delimiter withEncoding: (of_string_encoding_t)encoding { OFString *ret = nil; if ((ret = [self _tryReadTillDelimiter: delimiter withEncoding: encoding checkCache: YES]) != nil) return ret; while ((ret = [self _tryReadTillDelimiter: delimiter withEncoding: encoding checkCache: NO]) == nil) if ([self isAtEndOfStream]) return nil; return ret; } - (OFString*)tryReadTillDelimiter: (OFString*)delimiter { return [self tryReadTillDelimiter: delimiter withEncoding: OF_STRING_ENCODING_UTF_8]; } - (OFString*)tryReadTillDelimiter: (OFString*)delimiter withEncoding: (of_string_encoding_t)encoding { return [self _tryReadTillDelimiter: delimiter withEncoding: encoding checkCache: YES]; } - (BOOL)buffersWrites { return buffersWrites; } - (void)setBuffersWrites: (BOOL)enable { |
︙ | ︙ |