Skip to content

Commit b018db2

Browse files
authored
Merge pull request #866 from sdroege/inlining
Inline various trivial functions
2 parents 59cb4d2 + 2e2b91a commit b018db2

File tree

150 files changed

+1981
-489
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+1981
-489
lines changed

cairo/src/context.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct RectangleList {
2222
impl ops::Deref for RectangleList {
2323
type Target = [Rectangle];
2424

25+
#[inline]
2526
fn deref(&self) -> &[Rectangle] {
2627
unsafe {
2728
let ptr = (*self.ptr).rectangles as *mut Rectangle;
@@ -37,6 +38,7 @@ impl ops::Deref for RectangleList {
3738
}
3839

3940
impl Drop for RectangleList {
41+
#[inline]
4042
fn drop(&mut self) {
4143
unsafe {
4244
ffi::cairo_rectangle_list_destroy(self.ptr);
@@ -116,12 +118,14 @@ gvalue_impl!(
116118
);
117119

118120
impl Clone for Context {
121+
#[inline]
119122
fn clone(&self) -> Context {
120123
unsafe { Self::from_raw_none(self.to_raw_none()) }
121124
}
122125
}
123126

124127
impl Drop for Context {
128+
#[inline]
125129
fn drop(&mut self) {
126130
unsafe {
127131
ffi::cairo_destroy(self.0.as_ptr());
@@ -132,28 +136,30 @@ impl Drop for Context {
132136
impl Context {
133137
#[inline]
134138
pub unsafe fn from_raw_none(ptr: *mut ffi::cairo_t) -> Context {
135-
assert!(!ptr.is_null());
139+
debug_assert!(!ptr.is_null());
136140
ffi::cairo_reference(ptr);
137141
Context(ptr::NonNull::new_unchecked(ptr))
138142
}
139143

140144
#[inline]
141145
pub unsafe fn from_raw_borrow(ptr: *mut ffi::cairo_t) -> crate::Borrowed<Context> {
142-
assert!(!ptr.is_null());
146+
debug_assert!(!ptr.is_null());
143147
crate::Borrowed::new(Context(ptr::NonNull::new_unchecked(ptr)))
144148
}
145149

146150
#[inline]
147151
pub unsafe fn from_raw_full(ptr: *mut ffi::cairo_t) -> Context {
148-
assert!(!ptr.is_null());
152+
debug_assert!(!ptr.is_null());
149153
Context(ptr::NonNull::new_unchecked(ptr))
150154
}
151155

156+
#[inline]
152157
pub fn to_raw_none(&self) -> *mut ffi::cairo_t {
153158
self.0.as_ptr()
154159
}
155160

156161
#[doc(alias = "cairo_status")]
162+
#[inline]
157163
pub fn status(&self) -> Result<(), Error> {
158164
let status = unsafe { ffi::cairo_status(self.0.as_ptr()) };
159165
status_to_result(status)

cairo/src/device.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::{Content, RecordingSurface, ScriptMode, Surface};
2020
pub struct DeviceAcquireGuard<'a>(&'a Device);
2121

2222
impl<'a> Drop for DeviceAcquireGuard<'a> {
23+
#[inline]
2324
fn drop(&mut self) {
2425
self.0.release();
2526
}
@@ -31,22 +32,26 @@ impl<'a> Drop for DeviceAcquireGuard<'a> {
3132
pub struct Device(ptr::NonNull<ffi::cairo_device_t>);
3233

3334
impl Device {
35+
#[inline]
3436
pub unsafe fn from_raw_none(ptr: *mut ffi::cairo_device_t) -> Device {
35-
assert!(!ptr.is_null());
37+
debug_assert!(!ptr.is_null());
3638
ffi::cairo_device_reference(ptr);
3739
Device(ptr::NonNull::new_unchecked(ptr))
3840
}
3941

42+
#[inline]
4043
pub unsafe fn from_raw_borrow(ptr: *mut ffi::cairo_device_t) -> crate::Borrowed<Device> {
41-
assert!(!ptr.is_null());
44+
debug_assert!(!ptr.is_null());
4245
crate::Borrowed::new(Device(ptr::NonNull::new_unchecked(ptr)))
4346
}
4447

48+
#[inline]
4549
pub unsafe fn from_raw_full(ptr: *mut ffi::cairo_device_t) -> Device {
46-
assert!(!ptr.is_null());
50+
debug_assert!(!ptr.is_null());
4751
Device(ptr::NonNull::new_unchecked(ptr))
4852
}
4953

54+
#[inline]
5055
pub fn to_raw_none(&self) -> *mut ffi::cairo_device_t {
5156
self.0.as_ptr()
5257
}
@@ -286,6 +291,7 @@ impl Device {
286291
}
287292

288293
#[doc(alias = "cairo_device_status")]
294+
#[inline]
289295
pub fn status(&self) -> Result<(), Error> {
290296
let status = unsafe { ffi::cairo_device_status(self.to_raw_none()) };
291297
status_to_result(status)
@@ -352,12 +358,14 @@ gvalue_impl!(
352358
);
353359

354360
impl Clone for Device {
361+
#[inline]
355362
fn clone(&self) -> Device {
356363
unsafe { Self::from_raw_none(ffi::cairo_device_reference(self.0.as_ptr())) }
357364
}
358365
}
359366

360367
impl Drop for Device {
368+
#[inline]
361369
fn drop(&mut self) {
362370
unsafe {
363371
ffi::cairo_device_destroy(self.0.as_ptr());

cairo/src/enums.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::Error;
1212
macro_rules! gvalue_impl {
1313
($name:ty, $get_type:expr) => {
1414
impl glib::types::StaticType for $name {
15+
#[inline]
1516
fn static_type() -> glib::Type {
1617
unsafe { from_glib($get_type()) }
1718
}

cairo/src/font/font_face.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,33 +106,39 @@ impl FontFace {
106106
}
107107

108108
#[cfg(feature = "use_glib")]
109+
#[inline]
109110
pub unsafe fn from_raw_full(ptr: *mut ffi::cairo_font_face_t) -> FontFace {
110111
from_glib_full(ptr)
111112
}
112113

113114
#[cfg(not(feature = "use_glib"))]
115+
#[inline]
114116
pub unsafe fn from_raw_full(ptr: *mut ffi::cairo_font_face_t) -> FontFace {
115-
assert!(!ptr.is_null());
117+
debug_assert!(!ptr.is_null());
116118
FontFace(ptr::NonNull::new_unchecked(ptr))
117119
}
118120

119121
#[cfg(feature = "use_glib")]
122+
#[inline]
120123
pub unsafe fn from_raw_none(ptr: *mut ffi::cairo_font_face_t) -> FontFace {
121124
from_glib_none(ptr)
122125
}
123126

124127
#[cfg(not(feature = "use_glib"))]
128+
#[inline]
125129
pub unsafe fn from_raw_none(ptr: *mut ffi::cairo_font_face_t) -> FontFace {
126-
assert!(!ptr.is_null());
130+
debug_assert!(!ptr.is_null());
127131
FontFace(ptr::NonNull::new_unchecked(ptr))
128132
}
129133

130134
#[cfg(feature = "use_glib")]
135+
#[inline]
131136
pub fn to_raw_none(&self) -> *mut ffi::cairo_font_face_t {
132137
self.to_glib_none().0
133138
}
134139

135140
#[cfg(not(feature = "use_glib"))]
141+
#[inline]
136142
pub fn to_raw_none(&self) -> *mut ffi::cairo_font_face_t {
137143
self.0.as_ptr()
138144
}
@@ -197,6 +203,7 @@ impl FontFace {
197203

198204
#[cfg(not(feature = "use_glib"))]
199205
impl Drop for FontFace {
206+
#[inline]
200207
fn drop(&mut self) {
201208
unsafe {
202209
ffi::cairo_font_face_destroy(self.to_raw_none());
@@ -206,6 +213,7 @@ impl Drop for FontFace {
206213

207214
#[cfg(not(feature = "use_glib"))]
208215
impl Clone for FontFace {
216+
#[inline]
209217
fn clone(&self) -> FontFace {
210218
unsafe { FontFace::from_raw_none(self.to_raw_none()) }
211219
}

cairo/src/font/font_options.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,26 @@ impl FontOptions {
5252
}
5353

5454
#[cfg(feature = "use_glib")]
55+
#[inline]
5556
pub unsafe fn from_raw_full(ptr: *mut ffi::cairo_font_options_t) -> Self {
5657
from_glib_full(ptr)
5758
}
5859

5960
#[cfg(not(feature = "use_glib"))]
61+
#[inline]
6062
pub unsafe fn from_raw_full(ptr: *mut ffi::cairo_font_options_t) -> Self {
61-
assert!(!ptr.is_null());
63+
debug_assert!(!ptr.is_null());
6264
Self(ptr::NonNull::new_unchecked(ptr))
6365
}
6466

6567
#[cfg(feature = "use_glib")]
68+
#[inline]
6669
pub fn to_raw_none(&self) -> *mut ffi::cairo_font_options_t {
6770
mut_override(self.to_glib_none().0)
6871
}
6972

7073
#[cfg(not(feature = "use_glib"))]
74+
#[inline]
7175
pub fn to_raw_none(&self) -> *mut ffi::cairo_font_options_t {
7276
self.0.as_ptr()
7377
}
@@ -176,6 +180,7 @@ impl hash::Hash for FontOptions {
176180

177181
#[cfg(not(feature = "use_glib"))]
178182
impl Drop for FontOptions {
183+
#[inline]
179184
fn drop(&mut self) {
180185
unsafe {
181186
ffi::cairo_font_options_destroy(self.to_raw_none());
@@ -185,6 +190,7 @@ impl Drop for FontOptions {
185190

186191
#[cfg(not(feature = "use_glib"))]
187192
impl Clone for FontOptions {
193+
#[inline]
188194
fn clone(&self) -> FontOptions {
189195
unsafe { FontOptions::from_raw_full(ffi::cairo_font_options_copy(self.to_raw_none())) }
190196
}

cairo/src/font/scaled_font.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,40 @@ impl ScaledFont {
5151
}
5252

5353
#[cfg(feature = "use_glib")]
54+
#[inline]
5455
pub fn to_raw_none(&self) -> *mut ffi::cairo_scaled_font_t {
5556
self.to_glib_none().0
5657
}
5758

5859
#[cfg(not(feature = "use_glib"))]
60+
#[inline]
5961
pub fn to_raw_none(&self) -> *mut ffi::cairo_scaled_font_t {
6062
self.0.as_ptr()
6163
}
6264

6365
#[cfg(not(feature = "use_glib"))]
66+
#[inline]
6467
pub unsafe fn from_raw_full(ptr: *mut ffi::cairo_scaled_font_t) -> ScaledFont {
65-
assert!(!ptr.is_null());
68+
debug_assert!(!ptr.is_null());
6669
ScaledFont(ptr::NonNull::new_unchecked(ptr))
6770
}
6871

6972
#[cfg(feature = "use_glib")]
73+
#[inline]
7074
pub unsafe fn from_raw_full(ptr: *mut ffi::cairo_scaled_font_t) -> ScaledFont {
7175
from_glib_full(ptr)
7276
}
7377

7478
#[cfg(feature = "use_glib")]
79+
#[inline]
7580
pub unsafe fn from_raw_none(ptr: *mut ffi::cairo_scaled_font_t) -> ScaledFont {
7681
from_glib_none(ptr)
7782
}
7883

7984
#[cfg(not(feature = "use_glib"))]
85+
#[inline]
8086
pub unsafe fn from_raw_none(ptr: *mut ffi::cairo_scaled_font_t) -> ScaledFont {
81-
assert!(!ptr.is_null());
87+
debug_assert!(!ptr.is_null());
8288
ffi::cairo_scaled_font_reference(ptr);
8389
ScaledFont(ptr::NonNull::new_unchecked(ptr))
8490
}
@@ -260,6 +266,7 @@ impl ScaledFont {
260266

261267
#[cfg(not(feature = "use_glib"))]
262268
impl Drop for ScaledFont {
269+
#[inline]
263270
fn drop(&mut self) {
264271
unsafe {
265272
ffi::cairo_scaled_font_destroy(self.to_raw_none());
@@ -269,6 +276,7 @@ impl Drop for ScaledFont {
269276

270277
#[cfg(not(feature = "use_glib"))]
271278
impl Clone for ScaledFont {
279+
#[inline]
272280
fn clone(&self) -> ScaledFont {
273281
unsafe { ScaledFont::from_raw_none(self.to_raw_none()) }
274282
}

cairo/src/font/user_fonts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ impl UserFontFace {
241241
impl std::ops::Deref for UserFontFace {
242242
type Target = FontFace;
243243

244+
#[inline]
244245
fn deref(&self) -> &Self::Target {
245246
&self.0
246247
}

cairo/src/image_surface.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,14 @@ unsafe impl Send for ImageSurfaceDataOwned {}
179179
unsafe impl Sync for ImageSurfaceDataOwned {}
180180

181181
impl ImageSurfaceDataOwned {
182+
#[inline]
182183
pub fn into_inner(self) -> ImageSurface {
183184
self.surface
184185
}
185186
}
186187

187188
impl AsRef<[u8]> for ImageSurfaceDataOwned {
189+
#[inline]
188190
fn as_ref(&self) -> &[u8] {
189191
let len = (self.surface.stride() as usize) * (self.surface.height() as usize);
190192
unsafe {
@@ -198,6 +200,7 @@ impl AsRef<[u8]> for ImageSurfaceDataOwned {
198200
}
199201

200202
impl AsMut<[u8]> for ImageSurfaceDataOwned {
203+
#[inline]
201204
fn as_mut(&mut self) -> &mut [u8] {
202205
let len = (self.surface.stride() as usize) * (self.surface.height() as usize);
203206
unsafe {
@@ -213,12 +216,14 @@ impl AsMut<[u8]> for ImageSurfaceDataOwned {
213216
impl Deref for ImageSurfaceDataOwned {
214217
type Target = [u8];
215218

219+
#[inline]
216220
fn deref(&self) -> &Self::Target {
217221
self.as_ref()
218222
}
219223
}
220224

221225
impl DerefMut for ImageSurfaceDataOwned {
226+
#[inline]
222227
fn deref_mut(&mut self) -> &mut Self::Target {
223228
self.as_mut()
224229
}
@@ -253,6 +258,7 @@ impl<'a> ImageSurfaceData<'a> {
253258
}
254259

255260
impl<'a> Drop for ImageSurfaceData<'a> {
261+
#[inline]
256262
fn drop(&mut self) {
257263
if self.dirty {
258264
self.surface.mark_dirty()
@@ -263,12 +269,14 @@ impl<'a> Drop for ImageSurfaceData<'a> {
263269
impl<'a> Deref for ImageSurfaceData<'a> {
264270
type Target = [u8];
265271

272+
#[inline]
266273
fn deref(&self) -> &[u8] {
267274
self.slice
268275
}
269276
}
270277

271278
impl<'a> DerefMut for ImageSurfaceData<'a> {
279+
#[inline]
272280
fn deref_mut(&mut self) -> &mut [u8] {
273281
self.dirty = true;
274282
self.slice

0 commit comments

Comments
 (0)