aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRyan Stewart <ryan@binsoftware.com>2015-03-18 14:49:16 -0700
committerRyan Stewart <ryan@binsoftware.com>2015-03-18 14:49:16 -0700
commitcf630ec0416d89bde9fcc6d8bd3674a7c55ac1a5 (patch)
treeafa3486c4f9e1cb8f0bc2cd7d4191e1de231f5af /src
parent1b2fd6e6d01788922a90cd4e58adf371007f50a8 (diff)
downloadglutin-cf630ec0416d89bde9fcc6d8bd3674a7c55ac1a5.tar.gz
glutin-cf630ec0416d89bde9fcc6d8bd3674a7c55ac1a5.zip
add and use IdRef::non_nil() instead of doing deref'd comparisons against nil
Diffstat (limited to 'src')
-rw-r--r--src/cocoa/mod.rs51
1 files changed, 24 insertions, 27 deletions
diff --git a/src/cocoa/mod.rs b/src/cocoa/mod.rs
index f4b2726..62eedc6 100644
--- a/src/cocoa/mod.rs
+++ b/src/cocoa/mod.rs
@@ -456,10 +456,7 @@ impl Window {
NSBackingStoreBuffered,
NO,
));
-
- if *window == nil {
- None
- } else {
+ window.non_nil().map(|window| {
let title = IdRef::new(NSString::alloc(nil).init_str(title));
window.setTitle_(*title);
window.setAcceptsMouseMovedEvents_(YES);
@@ -469,21 +466,19 @@ impl Window {
else {
window.center();
}
- Some(window)
- }
+ window
+ })
}
}
fn create_view(window: id) -> Option<IdRef> {
unsafe {
let view = IdRef::new(NSView::alloc(nil).init());
- if *view == nil {
- None
- } else {
+ view.non_nil().map(|view| {
view.setWantsBestResolutionOpenGLSurface_(YES);
window.setContentView_(*view);
- Some(view)
- }
+ view
+ })
}
}
@@ -513,21 +508,17 @@ impl Window {
];
let pixelformat = IdRef::new(NSOpenGLPixelFormat::alloc(nil).initWithAttributes_(&attributes));
- if *pixelformat == nil {
- return None;
- }
-
- let context = IdRef::new(NSOpenGLContext::alloc(nil).initWithFormat_shareContext_(*pixelformat, nil));
- if *context == nil {
- None
- } else {
- context.setView_(view);
- if vsync {
- let value = 1;
- context.setValues_forParameter_(&value, NSOpenGLContextParameter::NSOpenGLCPSwapInterval);
- }
- Some(context)
- }
+ pixelformat.non_nil().map(|pixelformat| {
+ let context = IdRef::new(NSOpenGLContext::alloc(nil).initWithFormat_shareContext_(*pixelformat, nil));
+ context.non_nil().map(|context| {
+ context.setView_(view);
+ if vsync {
+ let value = 1;
+ context.setValues_forParameter_(&value, NSOpenGLContextParameter::NSOpenGLCPSwapInterval);
+ }
+ context
+ })
+ }).unwrap_or(None)
}
}
@@ -715,9 +706,15 @@ impl IdRef {
}
fn retain(i: id) -> IdRef {
- unsafe { msg_send::<()>()(i, selector("retain")) };
+ if i != nil {
+ unsafe { msg_send::<()>()(i, selector("retain")) };
+ }
IdRef(i)
}
+
+ fn non_nil(self) -> Option<IdRef> {
+ if self.0 == nil { None } else { Some(self) }
+ }
}
impl Drop for IdRef {