Skip to content

Commit 983ed38

Browse files
committed
feat: inline functions and more
1 parent 295ef48 commit 983ed38

27 files changed

+207
-122
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ set(LIB_SOURCE_FILES
9191
src/Closure.mm
9292
src/NativeCall.mm
9393
src/MethodCif.mm
94-
src/ObjCBridgeData.mm
9594
src/TypeConv.mm
9695
src/Util.mm
9796
src/Struct.mm
@@ -103,6 +102,7 @@ set(LIB_SOURCE_FILES
103102
src/CustomClass.mm
104103
src/CFunction.mm
105104
src/Interop.mm
105+
src/InlineFunctions.mm
106106
)
107107

108108
add_library(

bench/main.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
import "objc";
22
import { bench, run } from "mitata";
33

4+
{
5+
const arr = NSArray.array();
6+
7+
let total = 0;
8+
let n = 1e6;
9+
10+
for (let i = 0; i < n; i++) {
11+
const start = performance.now();
12+
arr.count;
13+
total += performance.now() - start;
14+
}
15+
16+
console.log("ns/iter:", total * 1e6 / n);
17+
}
18+
419
const arr = NSMutableArray.arrayWithCapacity(100);
520

621
const arr2 = new Proxy(arr, {

core-test/src/compat.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,3 @@ globalThis.__dirname = NSBundle.mainBundle.bundlePath;
88
WeakRef.prototype.get = function () {
99
return this.deref();
1010
};
11-
12-
globalThis.CGRectMake = function (x, y, width, height) {
13-
return { origin: { x, y }, size: { width, height } };
14-
};

include/Bridge.h

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

include/InlineFunctions.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef INLINE_FUNCTIONS_H
2+
#define INLINE_FUNCTIONS_H
3+
4+
#include "js_native_api.h"
5+
6+
namespace objc_bridge {
7+
8+
void registerInlineFunctions(napi_env env);
9+
10+
} // namespace objc_bridge
11+
12+
#endif /* INLINE_FUNCTIONS_H */

include/NativeCall.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef BRIDGED_METHOD_H
22
#define BRIDGED_METHOD_H
33

4-
#include "ObjCBridgeData.h"
4+
#include "ObjCBridge.h"
55
#include "objc/runtime.h"
66

77
namespace objc_bridge {
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef OBJC_BRIDGE_DATA_H
2-
#define OBJC_BRIDGE_DATA_H
1+
#ifndef OBJC_BRIDGE_H
2+
#define OBJC_BRIDGE_H
33

44
#include "AutoreleasePool.h"
55
#include "CFunction.h"
@@ -19,6 +19,9 @@
1919
#include <unordered_map>
2020
#include <unordered_set>
2121

22+
extern "C" void objc_bridge_init(napi_env env, const char *metadata_path);
23+
extern "C" napi_value napi_register_module_v1(napi_env env, napi_value exports);
24+
2225
using namespace metagen;
2326

2427
namespace objc_bridge {
@@ -138,4 +141,4 @@ class ObjCBridgeData {
138141

139142
} // namespace objc_bridge
140143

141-
#endif /* OBJC_BRIDGE_DATA_H */
144+
#endif /* OBJC_BRIDGE_H */

lib/inline_functions.d.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export {};
2+
3+
declare global {
4+
function CGMakePoint(x: number, y: number): { x: number; y: number };
5+
let NSMakePoint: typeof CGMakePoint;
6+
7+
function CGMakeSize(
8+
width: number,
9+
height: number,
10+
): { width: number; height: number };
11+
let NSMakeSize: typeof CGMakeSize;
12+
13+
function CGMakeRect(
14+
x: number,
15+
y: number,
16+
width: number,
17+
height: number,
18+
): {
19+
origin: { x: number; y: number };
20+
size: { width: number; height: number };
21+
};
22+
let NSMakeRect: typeof CGMakeRect;
23+
24+
function UIMakeEdgeInsets(
25+
top: number,
26+
left: number,
27+
bottom: number,
28+
right: number,
29+
): { top: number; left: number; bottom: number; right: number };
30+
31+
function NSMakeRange(
32+
location: number,
33+
length: number,
34+
): { location: number; length: number };
35+
}

lib/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference path="./inline_functions.d.ts" />
2+
13
// It's a module
24
export {};
35

src/Block.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "Block.h"
2-
#include "ObjCBridgeData.h"
2+
#include "ObjCBridge.h"
33
#include "node_api_util.h"
44
#include "objc/runtime.h"
55
#import <Foundation/Foundation.h>

0 commit comments

Comments
 (0)