This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
const long count = 10000000; | |
const char *str1 = "hellohello"; //fits in a tagged pointer | |
const char *str2 = "hellohelQo"; //at this character count, can only fit in a tagged pointer by using <8 bits per character, which requires dropping less frequently used chars like 'Q' | |
const char *str3 = "Northern Sami"; //this string is encountered frequently enough that it's baked into a perfect hash table in CoreFoundation | |
const char *str4 = "hellohellü"; //this string can't be tagged *and* can't be stored using an ASCII backing store | |
NSDate *start = [NSDate date]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We're a group of tech employees (@Catfish_Man, @jnadeau, @numist, @jauricchio, and @daagaak) interested in making sure | |
as many people as possible survive the current state of US politics. For each dollar we donate, our employer | |
will donate two. We're pooling our resources to do the same for you, so for each dollar you donate to the | |
orgs below, we'll also donate one dollar to those orgs, and our employer will donate two: quadruple your donation! | |
We have $45k set aside for this, so we'll keep matching donations until we've matched that much or 72 hours have passed. | |
You can send me a tweet/DM (@Catfish_Man) with a screenshot of evidence that you donated (receipt page, whatever works, we're not picky). | |
Southern Poverty Law Center | |
Council on American-Islamic Relations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static id cachedObject; | |
static NSLock *lock; | |
id getCachedObject() { | |
[lock lock]; | |
id result = [cachedObject retain]; | |
[lock unlock]; | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Let's Reinvent Modern CPU Caches! | |
In The Beginning, programs were hard-coded, entered directly with switches. Values would be input, and then results would output, | |
but couldn't really be stored. We'll draw this like so: | |
Input -> Fixed Calculations -> Output | |
An early improvement in generality was the addition of storage (ENIAC eventually gained 100 words of magnetic core memory), | |
leaving us with something along these lines: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Created by David Smith on 5/29/17. | |
// Copyright © 2017 Unseen University. All rights reserved. | |
// | |
// Localization- and encoding-safe solution to Coraline Ada's challenge here: https://twitter.com/CoralineAda/status/869204799027372032 | |
// Very lightly tested. Probably contains bugs. | |
import Foundation | |
func tweetStorm(input uncanonicalizedInput:String, handle:String?) -> [String] { | |
let input = uncanonicalizedInput.precomposedStringWithCanonicalMapping //twitter requires NFC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <time.h> | |
#import <os/lock.h> | |
#define ITERS 2000 | |
#define NSEC_PER_ITER(time) (((double)time * (double)NSEC_PER_SEC) / (double)ITERS) | |
#define TEST(body, name) do {\ | |
start = [NSDate date];\ | |
for (int i = 0; i < ITERS; i++) {\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As of iOS 11/macOS High Sierra, and only including ones in Foundation and CoreFoundation | |
Strings: | |
_NSCFString - a CFStringRef or CFMutableStringRef. This is the most common type of string object currently. | |
- May have 8 bit (ASCII) or 16 bit (UTF-16) backing store | |
_NSCFConstantString - a compile time constant CFStringRef, like you'd get with @"foo" | |
- May also be generated by dynamic string creation if matches a string in a pre-baked table of common strings called the StringROM | |
NSBigMutableString - an NSString backed by a CFStorage (https://github.com/opensource-apple/CF/blob/master/CFStorage.h) for faster handling of very large strings | |
NSCheapMutableString - a very limited NSMutableString that allows for zero-copy initialization. Used in NSFileManager for temporarily wrapping stack buffers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <assert.h> | |
//Compile with `clang -Os -framework Foundation -fno-objc-arc inlinestorage.m -o inline, run with `inline clever` or `inline naive` | |
/* | |
NaiveArray implements a simple immutable NSArray-like interface in probably the most obvious way: store a pointer to a C array of objects | |
*/ | |
@interface NaiveArray : NSObject { | |
NSUInteger count; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//compile with "clang -framework Foundation -arch i386 failbuzz.m -o FizzBuzz" | |
//Yes, it only works in 32 bit | |
//No, I can't fix it to work correctly past 12 without coming up with a new implementation strategy, | |
//or compiling a new CoreFoundation that caches more CFNumbers (…I did do that to be sure it worked though) | |
#import <Foundation/Foundation.h> | |
#import <libgen.h> | |
static void setup(const char * argv[]) { | |
for (int i = 1; i <= 100; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func g(_ x: inout Int) { | |
x = x * x | |
} | |
func f() { | |
var computed:Int { | |
get { return 5 } | |
set { print(newValue) } | |
} | |
g(&computed) |