Skip to content

Commit

Permalink
Cache class access
Browse files Browse the repository at this point in the history
  • Loading branch information
grovesNL committed Jul 16, 2018
1 parent 721def6 commit 14d1c78
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ block = "0.1.5"
foreign-types = "0.3"

[dependencies.objc]
version = "0.2.1"
version = "0.2.3"
features = ["objc_exception"]

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions src/argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use ::{Array, MTLTextureType};

use cocoa::foundation::NSUInteger;
use objc::runtime::{Class, YES, NO};
use objc::runtime::{YES, NO};
use objc_foundation::{NSString, INSString};

#[repr(u64)]
Expand Down Expand Up @@ -320,7 +320,7 @@ foreign_obj_type! {
impl ArgumentDescriptor {
pub fn new<'a>() -> &'a ArgumentDescriptorRef {
unsafe {
let class = Class::get("MTLArgumentDescriptor").unwrap();
let class = class!(MTLArgumentDescriptor);
msg_send![class, argumentDescriptor]
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/capturemanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use super::*;

use objc::runtime::Class;
use objc_foundation::{INSString, NSString};

pub enum MTLCaptureScope {}
Expand Down Expand Up @@ -50,7 +49,7 @@ foreign_obj_type! {
impl CaptureManager {
pub fn shared<'a>() -> &'a CaptureManagerRef {
unsafe {
let class = Class::get("MTLCaptureManager").unwrap();
let class = class!(MTLCaptureManager);
msg_send![class, sharedCaptureManager]
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/depthstencil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use objc::runtime::{Class, YES, NO};
use objc::runtime::{YES, NO};

#[repr(u64)]
pub enum MTLCompareFunction {
Expand Down Expand Up @@ -42,7 +42,7 @@ foreign_obj_type! {
impl StencilDescriptor {
pub fn new() -> Self {
unsafe {
let class = Class::get("MTLStencilDescriptor").unwrap();
let class = class!(MTLStencilDescriptor);
msg_send![class, new]
}
}
Expand Down Expand Up @@ -134,7 +134,7 @@ foreign_obj_type! {
impl DepthStencilDescriptor {
pub fn new() -> Self {
unsafe {
let class = Class::get("MTLDepthStencilDescriptor").unwrap();
let class = class!(MTLDepthStencilDescriptor);
msg_send![class, new]
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use super::*;

use cocoa::foundation::NSUInteger;
use objc::runtime::Class;

pub enum MTLHeap {}

Expand Down Expand Up @@ -90,7 +89,7 @@ foreign_obj_type! {
impl HeapDescriptor {
pub fn new() -> Self {
unsafe {
let class = Class::get("MTLHeapDescriptor").unwrap();
let class = class!(MTLHeapDescriptor);
msg_send![class, new]
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::marker::PhantomData;
use std::ops::Deref;
use std::borrow::{Borrow, ToOwned};

use objc::runtime::{Object, Class, YES, NO};
use objc::runtime::{Object, YES, NO};
use cocoa::foundation::NSSize;
use foreign_types::ForeignType;

Expand Down Expand Up @@ -159,14 +159,14 @@ impl<T> Array<T> where
{
pub fn from_slice(s: &[&T::Ref]) -> Self {
unsafe {
let class = Class::get("NSArray").unwrap();
let class = class!(NSArray);
msg_send![class, arrayWithObjects: s.as_ptr() count: s.len()]
}
}

pub fn from_owned_slice(s: &[T]) -> Self {
unsafe {
let class = Class::get("NSArray").unwrap();
let class = class!(NSArray);
msg_send![class, arrayWithObjects: s.as_ptr() count: s.len()]
}
}
Expand Down Expand Up @@ -254,7 +254,7 @@ foreign_obj_type! {
impl CoreAnimationLayer {
pub fn new() -> Self {
unsafe {
let class = Class::get("CAMetalLayer").unwrap();
let class = class!(CAMetalLayer);
msg_send![class, new]
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use super::*;

use objc::runtime::{Class, Object, YES, NO};
use objc::runtime::{Object, YES, NO};
use objc_foundation::{NSString, INSString, NSArray};
use cocoa::foundation::{NSUInteger};
use foreign_types::ForeignType;
Expand Down Expand Up @@ -123,7 +123,7 @@ foreign_obj_type! {
impl FunctionConstantValues {
pub fn new() -> Self {
unsafe {
let class = Class::get("MTLFunctionConstantValues").unwrap();
let class = class!(MTLFunctionConstantValues);
msg_send![class, new]
}
}
Expand All @@ -146,7 +146,7 @@ foreign_obj_type! {
impl CompileOptions {
pub fn new() -> Self {
unsafe {
let class = Class::get("MTLCompileOptions").unwrap();
let class = class!(MTLCompileOptions);
msg_send![class, new]
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/pipeline/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use super::*;

use cocoa::foundation::NSUInteger;
use objc::runtime::{Class, YES, NO};
use objc::runtime::{YES, NO};
use objc_foundation::{INSString, NSString};

#[repr(u64)]
Expand Down Expand Up @@ -109,7 +109,7 @@ foreign_obj_type! {
impl ComputePipelineDescriptor {
pub fn new() -> Self {
unsafe {
let class = Class::get("MTLComputePipelineDescriptor").unwrap();
let class = class!(MTLComputePipelineDescriptor);
msg_send![class, new]
}
}
Expand Down Expand Up @@ -280,7 +280,7 @@ foreign_obj_type! {
impl StageInputOutputDescriptor {
pub fn new<'a>() -> &'a StageInputOutputDescriptorRef {
unsafe {
let class = Class::get("MTLStageInputOutputDescriptor").unwrap();
let class = class!(MTLStageInputOutputDescriptor);
msg_send![class, stageInputOutputDescriptor]
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/pipeline/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use super::*;

use cocoa::foundation::NSUInteger;
use objc::runtime::{Class, Object, YES, NO};
use objc::runtime::{Object, YES, NO};
use objc_foundation::{INSString, NSString};

use libc;
Expand Down Expand Up @@ -203,7 +203,7 @@ impl RenderPipelineReflection {
fragment_data: *mut libc::c_void, vertex_desc: *mut libc::c_void,
device: &DeviceRef, options: u64, flags: u64) -> Self
{
let class = Class::get("MTLRenderPipelineReflection").unwrap();
let class = class!(MTLRenderPipelineReflection);
let this: RenderPipelineReflection = msg_send![class, alloc];
let this_alias: *mut Object = msg_send![this.as_ref(), initWithVertexData:vertex_data
fragmentData:fragment_data
Expand Down Expand Up @@ -243,7 +243,7 @@ foreign_obj_type! {
impl RenderPipelineDescriptor {
pub fn new() -> Self {
unsafe {
let class = Class::get("MTLRenderPipelineDescriptor").unwrap();
let class = class!(MTLRenderPipelineDescriptor);
msg_send![class, new]
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/renderpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use super::*;

use objc::runtime::Class;
use cocoa::foundation::NSUInteger;

#[repr(u64)]
Expand Down Expand Up @@ -189,7 +188,7 @@ foreign_obj_type! {
impl RenderPassColorAttachmentDescriptor {
pub fn new() -> Self {
unsafe {
let class = Class::get("MTLRenderPassColorAttachmentDescriptor").unwrap();
let class = class!(MTLRenderPassColorAttachmentDescriptor);
msg_send![class, new]
}
}
Expand Down Expand Up @@ -289,7 +288,7 @@ foreign_obj_type! {
impl RenderPassDescriptor {
pub fn new<'a>() -> &'a RenderPassDescriptorRef {
unsafe {
let class = Class::get("MTLRenderPassDescriptorInternal").unwrap();
let class = class!(MTLRenderPassDescriptorInternal);
msg_send![class, renderPassDescriptor]
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use objc::runtime::Class;
use cocoa::foundation::NSUInteger;

use depthstencil::MTLCompareFunction;
Expand Down Expand Up @@ -56,7 +55,7 @@ foreign_obj_type! {
impl SamplerDescriptor {
pub fn new() -> Self {
unsafe {
let class = Class::get("MTLSamplerDescriptor").unwrap();
let class = class!(MTLSamplerDescriptor);
msg_send![class, new]
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use super::*;

use cocoa::foundation::{NSUInteger, NSRange};
use objc::runtime::{Class, YES, NO};
use objc::runtime::{YES, NO};

use libc;

Expand Down Expand Up @@ -47,7 +47,7 @@ foreign_obj_type! {
impl TextureDescriptor {
pub fn new() -> Self {
unsafe {
let class = Class::get("MTLTextureDescriptor").unwrap();
let class = class!(MTLTextureDescriptor);
msg_send![class, new]
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/vertexdescriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use objc::runtime::Class;
use cocoa::foundation::NSUInteger;

use libc;
Expand Down Expand Up @@ -86,7 +85,7 @@ foreign_obj_type! {
impl VertexBufferLayoutDescriptor {
pub fn new () -> Self {
unsafe {
let class = Class::get("MTLVertexBufferLayoutDescriptor").unwrap();
let class = class!(MTLVertexBufferLayoutDescriptor);
msg_send![class, new]
}
}
Expand Down Expand Up @@ -164,7 +163,7 @@ foreign_obj_type! {
impl VertexAttributeDescriptor {
pub fn new() -> Self {
unsafe {
let class = Class::get("MTLVertexAttributeDescriptor").unwrap();
let class = class!(MTLVertexAttributeDescriptor);
msg_send![class, new]
}
}
Expand Down Expand Up @@ -242,7 +241,7 @@ foreign_obj_type! {
impl VertexDescriptor {
pub fn new<'a>() -> &'a VertexDescriptorRef {
unsafe {
let class = Class::get("MTLVertexDescriptor").unwrap();
let class = class!(MTLVertexDescriptor);
msg_send![class, vertexDescriptor]
}
}
Expand Down

0 comments on commit 14d1c78

Please sign in to comment.