Skip to content

Commit c7f1efe

Browse files
bors[bot]grovesNL
andcommitted
Merge #61
61: Cache class access r=kvark a=grovesNL - Uses [objc's new `class` macro](SSheldon/rust-objc#65) to cache all class accesses - Bumps the crate version to 0.10.3 Co-authored-by: Joshua Groves <[email protected]>
2 parents 721def6 + 822d219 commit c7f1efe

13 files changed

+30
-35
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "metal-rs"
3-
version = "0.10.2"
3+
version = "0.10.3"
44
description = "Rust bindings for Metal"
55
documentation = "https://docs.rs/crate/metal-rs"
66
homepage = "https://github.com/gfx-rs/metal-rs"
@@ -24,7 +24,7 @@ block = "0.1.5"
2424
foreign-types = "0.3"
2525

2626
[dependencies.objc]
27-
version = "0.2.1"
27+
version = "0.2.3"
2828
features = ["objc_exception"]
2929

3030
[dev-dependencies]

src/argument.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use ::{Array, MTLTextureType};
99

1010
use cocoa::foundation::NSUInteger;
11-
use objc::runtime::{Class, YES, NO};
11+
use objc::runtime::{YES, NO};
1212
use objc_foundation::{NSString, INSString};
1313

1414
#[repr(u64)]
@@ -320,7 +320,7 @@ foreign_obj_type! {
320320
impl ArgumentDescriptor {
321321
pub fn new<'a>() -> &'a ArgumentDescriptorRef {
322322
unsafe {
323-
let class = Class::get("MTLArgumentDescriptor").unwrap();
323+
let class = class!(MTLArgumentDescriptor);
324324
msg_send![class, argumentDescriptor]
325325
}
326326
}

src/capturemanager.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use super::*;
99

10-
use objc::runtime::Class;
1110
use objc_foundation::{INSString, NSString};
1211

1312
pub enum MTLCaptureScope {}
@@ -50,7 +49,7 @@ foreign_obj_type! {
5049
impl CaptureManager {
5150
pub fn shared<'a>() -> &'a CaptureManagerRef {
5251
unsafe {
53-
let class = Class::get("MTLCaptureManager").unwrap();
52+
let class = class!(MTLCaptureManager);
5453
msg_send![class, sharedCaptureManager]
5554
}
5655
}

src/depthstencil.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// http://opensource.org/licenses/MIT>, at your option. This file may not be
66
// copied, modified, or distributed except according to those terms.
77

8-
use objc::runtime::{Class, YES, NO};
8+
use objc::runtime::{YES, NO};
99

1010
#[repr(u64)]
1111
pub enum MTLCompareFunction {
@@ -42,7 +42,7 @@ foreign_obj_type! {
4242
impl StencilDescriptor {
4343
pub fn new() -> Self {
4444
unsafe {
45-
let class = Class::get("MTLStencilDescriptor").unwrap();
45+
let class = class!(MTLStencilDescriptor);
4646
msg_send![class, new]
4747
}
4848
}
@@ -134,7 +134,7 @@ foreign_obj_type! {
134134
impl DepthStencilDescriptor {
135135
pub fn new() -> Self {
136136
unsafe {
137-
let class = Class::get("MTLDepthStencilDescriptor").unwrap();
137+
let class = class!(MTLDepthStencilDescriptor);
138138
msg_send![class, new]
139139
}
140140
}

src/heap.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use super::*;
99

1010
use cocoa::foundation::NSUInteger;
11-
use objc::runtime::Class;
1211

1312
pub enum MTLHeap {}
1413

@@ -90,7 +89,7 @@ foreign_obj_type! {
9089
impl HeapDescriptor {
9190
pub fn new() -> Self {
9291
unsafe {
93-
let class = Class::get("MTLHeapDescriptor").unwrap();
92+
let class = class!(MTLHeapDescriptor);
9493
msg_send![class, new]
9594
}
9695
}

src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use std::marker::PhantomData;
2727
use std::ops::Deref;
2828
use std::borrow::{Borrow, ToOwned};
2929

30-
use objc::runtime::{Object, Class, YES, NO};
30+
use objc::runtime::{Object, YES, NO};
3131
use cocoa::foundation::NSSize;
3232
use foreign_types::ForeignType;
3333

@@ -159,14 +159,14 @@ impl<T> Array<T> where
159159
{
160160
pub fn from_slice(s: &[&T::Ref]) -> Self {
161161
unsafe {
162-
let class = Class::get("NSArray").unwrap();
162+
let class = class!(NSArray);
163163
msg_send![class, arrayWithObjects: s.as_ptr() count: s.len()]
164164
}
165165
}
166166

167167
pub fn from_owned_slice(s: &[T]) -> Self {
168168
unsafe {
169-
let class = Class::get("NSArray").unwrap();
169+
let class = class!(NSArray);
170170
msg_send![class, arrayWithObjects: s.as_ptr() count: s.len()]
171171
}
172172
}
@@ -254,7 +254,7 @@ foreign_obj_type! {
254254
impl CoreAnimationLayer {
255255
pub fn new() -> Self {
256256
unsafe {
257-
let class = Class::get("CAMetalLayer").unwrap();
257+
let class = class!(CAMetalLayer);
258258
msg_send![class, new]
259259
}
260260
}

src/library.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use super::*;
99

10-
use objc::runtime::{Class, Object, YES, NO};
10+
use objc::runtime::{Object, YES, NO};
1111
use objc_foundation::{NSString, INSString, NSArray};
1212
use cocoa::foundation::{NSUInteger};
1313
use foreign_types::ForeignType;
@@ -123,7 +123,7 @@ foreign_obj_type! {
123123
impl FunctionConstantValues {
124124
pub fn new() -> Self {
125125
unsafe {
126-
let class = Class::get("MTLFunctionConstantValues").unwrap();
126+
let class = class!(MTLFunctionConstantValues);
127127
msg_send![class, new]
128128
}
129129
}
@@ -146,7 +146,7 @@ foreign_obj_type! {
146146
impl CompileOptions {
147147
pub fn new() -> Self {
148148
unsafe {
149-
let class = Class::get("MTLCompileOptions").unwrap();
149+
let class = class!(MTLCompileOptions);
150150
msg_send![class, new]
151151
}
152152
}

src/pipeline/compute.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use super::*;
99

1010
use cocoa::foundation::NSUInteger;
11-
use objc::runtime::{Class, YES, NO};
11+
use objc::runtime::{YES, NO};
1212
use objc_foundation::{INSString, NSString};
1313

1414
#[repr(u64)]
@@ -109,7 +109,7 @@ foreign_obj_type! {
109109
impl ComputePipelineDescriptor {
110110
pub fn new() -> Self {
111111
unsafe {
112-
let class = Class::get("MTLComputePipelineDescriptor").unwrap();
112+
let class = class!(MTLComputePipelineDescriptor);
113113
msg_send![class, new]
114114
}
115115
}
@@ -280,7 +280,7 @@ foreign_obj_type! {
280280
impl StageInputOutputDescriptor {
281281
pub fn new<'a>() -> &'a StageInputOutputDescriptorRef {
282282
unsafe {
283-
let class = Class::get("MTLStageInputOutputDescriptor").unwrap();
283+
let class = class!(MTLStageInputOutputDescriptor);
284284
msg_send![class, stageInputOutputDescriptor]
285285
}
286286
}

src/pipeline/render.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use super::*;
99

1010
use cocoa::foundation::NSUInteger;
11-
use objc::runtime::{Class, Object, YES, NO};
11+
use objc::runtime::{Object, YES, NO};
1212
use objc_foundation::{INSString, NSString};
1313

1414
use libc;
@@ -203,7 +203,7 @@ impl RenderPipelineReflection {
203203
fragment_data: *mut libc::c_void, vertex_desc: *mut libc::c_void,
204204
device: &DeviceRef, options: u64, flags: u64) -> Self
205205
{
206-
let class = Class::get("MTLRenderPipelineReflection").unwrap();
206+
let class = class!(MTLRenderPipelineReflection);
207207
let this: RenderPipelineReflection = msg_send![class, alloc];
208208
let this_alias: *mut Object = msg_send![this.as_ref(), initWithVertexData:vertex_data
209209
fragmentData:fragment_data
@@ -243,7 +243,7 @@ foreign_obj_type! {
243243
impl RenderPipelineDescriptor {
244244
pub fn new() -> Self {
245245
unsafe {
246-
let class = Class::get("MTLRenderPipelineDescriptor").unwrap();
246+
let class = class!(MTLRenderPipelineDescriptor);
247247
msg_send![class, new]
248248
}
249249
}

src/renderpass.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use super::*;
99

10-
use objc::runtime::Class;
1110
use cocoa::foundation::NSUInteger;
1211

1312
#[repr(u64)]
@@ -189,7 +188,7 @@ foreign_obj_type! {
189188
impl RenderPassColorAttachmentDescriptor {
190189
pub fn new() -> Self {
191190
unsafe {
192-
let class = Class::get("MTLRenderPassColorAttachmentDescriptor").unwrap();
191+
let class = class!(MTLRenderPassColorAttachmentDescriptor);
193192
msg_send![class, new]
194193
}
195194
}
@@ -289,7 +288,7 @@ foreign_obj_type! {
289288
impl RenderPassDescriptor {
290289
pub fn new<'a>() -> &'a RenderPassDescriptorRef {
291290
unsafe {
292-
let class = Class::get("MTLRenderPassDescriptorInternal").unwrap();
291+
let class = class!(MTLRenderPassDescriptorInternal);
293292
msg_send![class, renderPassDescriptor]
294293
}
295294
}

src/sampler.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// http://opensource.org/licenses/MIT>, at your option. This file may not be
66
// copied, modified, or distributed except according to those terms.
77

8-
use objc::runtime::Class;
98
use cocoa::foundation::NSUInteger;
109

1110
use depthstencil::MTLCompareFunction;
@@ -56,7 +55,7 @@ foreign_obj_type! {
5655
impl SamplerDescriptor {
5756
pub fn new() -> Self {
5857
unsafe {
59-
let class = Class::get("MTLSamplerDescriptor").unwrap();
58+
let class = class!(MTLSamplerDescriptor);
6059
msg_send![class, new]
6160
}
6261
}

src/texture.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use super::*;
99

1010
use cocoa::foundation::{NSUInteger, NSRange};
11-
use objc::runtime::{Class, YES, NO};
11+
use objc::runtime::{YES, NO};
1212

1313
use libc;
1414

@@ -47,7 +47,7 @@ foreign_obj_type! {
4747
impl TextureDescriptor {
4848
pub fn new() -> Self {
4949
unsafe {
50-
let class = Class::get("MTLTextureDescriptor").unwrap();
50+
let class = class!(MTLTextureDescriptor);
5151
msg_send![class, new]
5252
}
5353
}

src/vertexdescriptor.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// http://opensource.org/licenses/MIT>, at your option. This file may not be
66
// copied, modified, or distributed except according to those terms.
77

8-
use objc::runtime::Class;
98
use cocoa::foundation::NSUInteger;
109

1110
use libc;
@@ -86,7 +85,7 @@ foreign_obj_type! {
8685
impl VertexBufferLayoutDescriptor {
8786
pub fn new () -> Self {
8887
unsafe {
89-
let class = Class::get("MTLVertexBufferLayoutDescriptor").unwrap();
88+
let class = class!(MTLVertexBufferLayoutDescriptor);
9089
msg_send![class, new]
9190
}
9291
}
@@ -164,7 +163,7 @@ foreign_obj_type! {
164163
impl VertexAttributeDescriptor {
165164
pub fn new() -> Self {
166165
unsafe {
167-
let class = Class::get("MTLVertexAttributeDescriptor").unwrap();
166+
let class = class!(MTLVertexAttributeDescriptor);
168167
msg_send![class, new]
169168
}
170169
}
@@ -242,7 +241,7 @@ foreign_obj_type! {
242241
impl VertexDescriptor {
243242
pub fn new<'a>() -> &'a VertexDescriptorRef {
244243
unsafe {
245-
let class = Class::get("MTLVertexDescriptor").unwrap();
244+
let class = class!(MTLVertexDescriptor);
246245
msg_send![class, vertexDescriptor]
247246
}
248247
}

0 commit comments

Comments
 (0)