Skip to content

Commit 7946d41

Browse files
committed
Updated to version 2.2
1 parent 9ccb065 commit 7946d41

File tree

15 files changed

+161
-42
lines changed

15 files changed

+161
-42
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
language: objective-c
2-
before_script:
3-
- brew update
4-
- brew upgrade xctool
52
script: xctool test -project Tests/UnitTests.xcodeproj -scheme UnitTests -sdk iphonesimulator

Benchmarks/Coding Benchmark/Benchmark.xcodeproj/project.pbxproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
017E2FEE1855CE9D004AE6E4 /* Sources */,
204204
017E2FEF1855CE9D004AE6E4 /* Frameworks */,
205205
017E2FF01855CE9D004AE6E4 /* CopyFiles */,
206+
13535D12198A9E8800BBC59F /* ShellScript */,
206207
);
207208
buildRules = (
208209
);
@@ -272,6 +273,24 @@
272273
};
273274
/* End PBXResourcesBuildPhase section */
274275

276+
/* Begin PBXShellScriptBuildPhase section */
277+
13535D12198A9E8800BBC59F /* ShellScript */ = {
278+
isa = PBXShellScriptBuildPhase;
279+
buildActionMask = 2147483647;
280+
files = (
281+
);
282+
inputPaths = (
283+
"${SRCROOT}/TestData.json",
284+
);
285+
outputPaths = (
286+
"${SRCROOT}/MacBenchmark/TestData.h",
287+
);
288+
runOnlyForDeploymentPostprocessing = 0;
289+
shellPath = /bin/sh;
290+
shellScript = "cd \"${SRCROOT}/\"\n/usr/bin/xxd -i \"TestData.json\" \"MacBenchmark/TestData.h\"\n";
291+
};
292+
/* End PBXShellScriptBuildPhase section */
293+
275294
/* Begin PBXSourcesBuildPhase section */
276295
017E2FEE1855CE9D004AE6E4 /* Sources */ = {
277296
isa = PBXSourcesBuildPhase;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
unsigned char TestData_json[] = {};
2+
unsigned int TestData_json_len = 0;

Benchmarks/Coding Benchmark/MacBenchmark/main.m

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@
99
#import <Foundation/Foundation.h>
1010
#import "FastCoder.h"
1111

12+
// the TestData.h file will be created at build time using the following shell script
13+
14+
// cd "${SRCROOT}/"
15+
// /usr/bin/xxd -i "TestData.json" "MacBenchmark/TestData.h"
16+
17+
// which converts the TestData.json file into a header containing the following:
18+
19+
// unsigned char TestData_json[] = {...};
20+
// unsigned int TestData_json_len = ...;
21+
22+
extern unsigned char TestData_json[];
23+
extern unsigned int TestData_json_len;
24+
25+
#import "TestData.h"
26+
1227

1328
void LogLoading(NSString *, NSTimeInterval, NSTimeInterval, NSTimeInterval);
1429
void LogLoading(NSString *name, NSTimeInterval start, NSTimeInterval loaded, NSTimeInterval parsed)
@@ -28,8 +43,8 @@ int main(__unused int argc, __unused const char * argv[])
2843
{
2944
@autoreleasepool
3045
{
31-
NSString *testInputPath = @"/Users/nick/Dropbox/Open Source (GIT)/FastCoding/Benchmarks/Coding Benchmark/TestData.json";
32-
NSData *data = [NSData dataWithContentsOfFile:testInputPath];
46+
//load test data (encoded in the generated TestData.h file)
47+
NSData *data = [NSData dataWithBytes:TestData_json length:TestData_json_len];
3348
id object = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingOptions)0 error:NULL];
3449

3550
NSString *KeyedArchivePath = [NSTemporaryDirectory() stringByAppendingString:@"test.nscoded"];

Benchmarks/Plist Benchmark/Benchmark.xcodeproj/project.pbxproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
017E2FEE1855CE9D004AE6E4 /* Sources */,
184184
017E2FEF1855CE9D004AE6E4 /* Frameworks */,
185185
017E2FF01855CE9D004AE6E4 /* CopyFiles */,
186+
13F216C7198AA1EE00173DF2 /* ShellScript */,
186187
);
187188
buildRules = (
188189
);
@@ -252,6 +253,24 @@
252253
};
253254
/* End PBXResourcesBuildPhase section */
254255

256+
/* Begin PBXShellScriptBuildPhase section */
257+
13F216C7198AA1EE00173DF2 /* ShellScript */ = {
258+
isa = PBXShellScriptBuildPhase;
259+
buildActionMask = 2147483647;
260+
files = (
261+
);
262+
inputPaths = (
263+
"${SRCROOT}/TestData.json",
264+
);
265+
outputPaths = (
266+
"${SRCROOT}/MacBenchmark/TestData.h",
267+
);
268+
runOnlyForDeploymentPostprocessing = 0;
269+
shellPath = /bin/sh;
270+
shellScript = "cd \"${SRCROOT}/\"\n/usr/bin/xxd -i \"TestData.json\" \"MacBenchmark/TestData.h\"\n";
271+
};
272+
/* End PBXShellScriptBuildPhase section */
273+
255274
/* Begin PBXSourcesBuildPhase section */
256275
017E2FEE1855CE9D004AE6E4 /* Sources */ = {
257276
isa = PBXSourcesBuildPhase;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
unsigned char TestData_json[] = {};
2+
unsigned int TestData_json_len = 0;

Benchmarks/Plist Benchmark/MacBenchmark/main.m

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@
99
#import <Foundation/Foundation.h>
1010
#import "FastCoder.h"
1111

12+
// the TestData.h file will be created at build time using the following shell script
13+
14+
// cd "${SRCROOT}/"
15+
// /usr/bin/xxd -i "TestData.json" "MacBenchmark/TestData.h"
16+
17+
// which converts the TestData.json file into a header containing the following:
18+
19+
// unsigned char TestData_json[] = {...};
20+
// unsigned int TestData_json_len = ...;
21+
22+
extern unsigned char TestData_json[];
23+
extern unsigned int TestData_json_len;
24+
25+
#import "TestData.h"
26+
1227

1328
void LogLoading(NSString *, NSTimeInterval, NSTimeInterval, NSTimeInterval);
1429
void LogLoading(NSString *name, NSTimeInterval start, NSTimeInterval loaded, NSTimeInterval parsed)
@@ -28,8 +43,8 @@ int main(__unused int argc, __unused const char * argv[])
2843
{
2944
@autoreleasepool
3045
{
31-
NSString *testInputPath = @"/Users/nick/Dropbox/Open Source (GIT)/FastCoding/Benchmarks/Plist Benchmark/TestData.json";
32-
NSData *data = [NSData dataWithContentsOfFile:testInputPath];
46+
//load test data (encoded in the generated TestData.h file)
47+
NSData *data = [NSData dataWithBytes:TestData_json length:TestData_json_len];
3348
id object = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingOptions)0 error:NULL];
3449

3550
NSString *JSONPath = [NSTemporaryDirectory() stringByAppendingString:@"test.json"];

FastCoder/FastCoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FastCoding.h
33
//
4-
// Version 2.1.9
4+
// Version 2.2
55
//
66
// Created by Nick Lockwood on 09/12/2013.
77
// Copyright (c) 2013 Charcoal Design

FastCoder/FastCoder.m

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FastCoding.m
33
//
4-
// Version 2.1.9
4+
// Version 2.2
55
//
66
// Created by Nick Lockwood on 09/12/2013.
77
// Copyright (c) 2013 Charcoal Design
@@ -54,7 +54,7 @@
5454

5555
static const uint32_t FCIdentifier = 'FAST';
5656
static const uint16_t FCMajorVersion = 2;
57-
static const uint16_t FCMinorVersion = 1;
57+
static const uint16_t FCMinorVersion = 2;
5858

5959

6060
typedef struct
@@ -608,7 +608,8 @@ static id FCReadMutableIndexSet(NSUInteger *offset, const void *input, NSUIntege
608608
uint32_t rangeCount = FCReadUInt32(offset, input, total);
609609
__autoreleasing NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
610610
FCCacheReadObject(indexSet, cache);
611-
for (uint32_t i=0; i<rangeCount; i++) {
611+
for (uint32_t i = 0; i < rangeCount; i++)
612+
{
612613
NSRange range = {FCReadUInt32(offset, input, total), FCReadUInt32(offset, input, total)};
613614
[indexSet addIndexesInRange:range];
614615
}
@@ -617,7 +618,18 @@ static id FCReadMutableIndexSet(NSUInteger *offset, const void *input, NSUIntege
617618

618619
static id FCReadIndexSet(NSUInteger *offset, const void *input, NSUInteger total, __unsafe_unretained id cache)
619620
{
620-
return [FCReadMutableIndexSet(offset, input, total, cache) copy];
621+
uint32_t rangeCount = FCReadUInt32(offset, input, total);
622+
if (rangeCount == 1)
623+
{
624+
//common case optimisation
625+
NSRange range = {FCReadUInt32(offset, input, total), FCReadUInt32(offset, input, total)};
626+
return [NSIndexSet indexSetWithIndexesInRange:range];
627+
}
628+
else
629+
{
630+
*offset -= sizeof(uint32_t);
631+
return [FCReadMutableIndexSet(offset, input, total, cache) copy];
632+
}
621633
}
622634

623635
static id FCReadObject(NSUInteger *offset, const void *input, NSUInteger total, __unsafe_unretained id cache)
@@ -962,16 +974,16 @@ - (void)FC_writeToOutput:(__unsafe_unretained NSMutableData *)output rootObject:
962974
BOOL mutable = ([self classForCoder] == [NSMutableIndexSet class]);
963975
if (mutable) FCCacheWrittenObject(self, cache);
964976

965-
NSUInteger __block rangeCount = 0; // I wish we could get this directly from NSSet...
966-
[self enumerateRangesUsingBlock:^(NSRange range, BOOL *stop) {
967-
rangeCount += 1;
977+
uint32_t __block rangeCount = 0; // I wish we could get this directly from NSSet...
978+
[self enumerateRangesUsingBlock:^(__unused NSRange range, __unused BOOL *stop) {
979+
rangeCount ++;
968980
}];
969981

970982
FCWriteUInt32(FCTypeIndexSet, output);
971983
FCWriteUInt32(rangeCount, output);
972-
[self enumerateRangesUsingBlock:^(NSRange range, BOOL *stop) {
973-
FCWriteUInt32(range.location, output);
974-
FCWriteUInt32(range.length, output);
984+
[self enumerateRangesUsingBlock:^(NSRange range, __unused BOOL *stop) {
985+
FCWriteUInt32((uint32_t)range.location, output);
986+
FCWriteUInt32((uint32_t)range.length, output);
975987
}];
976988

977989
if (!mutable) FCCacheWrittenObject(self, cache);

FastCoding.podspec

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)