2 * Copyright (c) 2006 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 /* Support for optimized accessor methods. Currently optimized accessor methods are provided for ivar offsets from 0 to 64. */
26 #define ALWAYS_USE_C_ACCESSOR_METHODS 0
28 // set of property getters for specific offsets.
29 #define GETPROPERTY_OFFSET(offset) _objc_getProperty_offset_ ## offset
30 #define DECLARE_GETPROPERTY_OFFSET(offset) extern id GETPROPERTY_OFFSET(offset)(id self, SEL _cmd)
31 #define IMPLEMENT_GETPROPERTY_OFFSET(offset) static id GETPROPERTY_OFFSET(offset)(id self, SEL _cmd) { return *(id*)((char*)self + offset); }
33 #if ALWAYS_USE_C_ACCESSOR_METHODS || defined(__ppc__) || defined(__ppc64__) || defined(__x86_64__)
34 // C versions with hard-coded offsets. may be good enough in most cases.
35 IMPLEMENT_GETPROPERTY_OFFSET(0)
36 IMPLEMENT_GETPROPERTY_OFFSET(4)
37 IMPLEMENT_GETPROPERTY_OFFSET(8)
38 IMPLEMENT_GETPROPERTY_OFFSET(12)
39 IMPLEMENT_GETPROPERTY_OFFSET(16)
40 IMPLEMENT_GETPROPERTY_OFFSET(20)
41 IMPLEMENT_GETPROPERTY_OFFSET(24)
42 IMPLEMENT_GETPROPERTY_OFFSET(28)
43 IMPLEMENT_GETPROPERTY_OFFSET(32)
44 IMPLEMENT_GETPROPERTY_OFFSET(36)
45 IMPLEMENT_GETPROPERTY_OFFSET(40)
46 IMPLEMENT_GETPROPERTY_OFFSET(44)
47 IMPLEMENT_GETPROPERTY_OFFSET(48)
48 IMPLEMENT_GETPROPERTY_OFFSET(52)
49 IMPLEMENT_GETPROPERTY_OFFSET(56)
50 IMPLEMENT_GETPROPERTY_OFFSET(60)
51 IMPLEMENT_GETPROPERTY_OFFSET(64)
53 // forward delcarations to assembly versions. only on i386 right now.
54 DECLARE_GETPROPERTY_OFFSET(0);
55 DECLARE_GETPROPERTY_OFFSET(4);
56 DECLARE_GETPROPERTY_OFFSET(8);
57 DECLARE_GETPROPERTY_OFFSET(12);
58 DECLARE_GETPROPERTY_OFFSET(16);
59 DECLARE_GETPROPERTY_OFFSET(20);
60 DECLARE_GETPROPERTY_OFFSET(24);
61 DECLARE_GETPROPERTY_OFFSET(28);
62 DECLARE_GETPROPERTY_OFFSET(32);
63 DECLARE_GETPROPERTY_OFFSET(36);
64 DECLARE_GETPROPERTY_OFFSET(40);
65 DECLARE_GETPROPERTY_OFFSET(44);
66 DECLARE_GETPROPERTY_OFFSET(48);
67 DECLARE_GETPROPERTY_OFFSET(52);
68 DECLARE_GETPROPERTY_OFFSET(56);
69 DECLARE_GETPROPERTY_OFFSET(60);
70 DECLARE_GETPROPERTY_OFFSET(64);
73 static void* _getProperty_offset_table
[] = {
74 GETPROPERTY_OFFSET(0),
75 GETPROPERTY_OFFSET(4),
76 GETPROPERTY_OFFSET(8),
77 GETPROPERTY_OFFSET(12),
78 GETPROPERTY_OFFSET(16),
79 GETPROPERTY_OFFSET(20),
80 GETPROPERTY_OFFSET(24),
81 GETPROPERTY_OFFSET(28),
82 GETPROPERTY_OFFSET(32),
83 GETPROPERTY_OFFSET(36),
84 GETPROPERTY_OFFSET(40),
85 GETPROPERTY_OFFSET(44),
86 GETPROPERTY_OFFSET(48),
87 GETPROPERTY_OFFSET(52),
88 GETPROPERTY_OFFSET(56),
89 GETPROPERTY_OFFSET(60),
90 GETPROPERTY_OFFSET(64),
93 #undef GETPROPERTY_OFFSET
94 #undef DECLARE_GETPROPERTY_OFFSET
95 #undef IMPLEMENT_GETPROPERTY_OFFSET
96 #define GETPROPERTY_IMP(offset) ((offset <= 64) ? (IMP)_getProperty_offset_table[offset >> 2] : NULL)
98 // set of property setters for specific offsets.
99 #define SETPROPERTY_OFFSET(offset) _objc_setProperty_offset_ ## offset
100 #define DECLARE_SETPROPERTY_OFFSET(offset) extern id SETPROPERTY_OFFSET(offset)(id self, SEL _cmd, ...)
101 #define IMPLEMENT_SETPROPERTY_OFFSET(offset) __private_extern__ void SETPROPERTY_OFFSET(offset)(id self, SEL _cmd, id value) { objc_assign_ivar_gc(value, self, offset); }
103 #if ALWAYS_USE_C_ACCESSOR_METHODS || !defined(__i386__)
104 // C versions with hard-coded offsets. may be good enough in most cases.
105 IMPLEMENT_SETPROPERTY_OFFSET(0)
106 IMPLEMENT_SETPROPERTY_OFFSET(4)
107 IMPLEMENT_SETPROPERTY_OFFSET(8)
108 IMPLEMENT_SETPROPERTY_OFFSET(12)
109 IMPLEMENT_SETPROPERTY_OFFSET(16)
110 IMPLEMENT_SETPROPERTY_OFFSET(20)
111 IMPLEMENT_SETPROPERTY_OFFSET(24)
112 IMPLEMENT_SETPROPERTY_OFFSET(28)
113 IMPLEMENT_SETPROPERTY_OFFSET(32)
114 IMPLEMENT_SETPROPERTY_OFFSET(36)
115 IMPLEMENT_SETPROPERTY_OFFSET(40)
116 IMPLEMENT_SETPROPERTY_OFFSET(44)
117 IMPLEMENT_SETPROPERTY_OFFSET(48)
118 IMPLEMENT_SETPROPERTY_OFFSET(52)
119 IMPLEMENT_SETPROPERTY_OFFSET(56)
120 IMPLEMENT_SETPROPERTY_OFFSET(60)
121 IMPLEMENT_SETPROPERTY_OFFSET(64)
123 // forward delcarations to assembly versions. only on i386 right now.
124 DECLARE_SETPROPERTY_OFFSET(0);
125 DECLARE_SETPROPERTY_OFFSET(4);
126 DECLARE_SETPROPERTY_OFFSET(8);
127 DECLARE_SETPROPERTY_OFFSET(12);
128 DECLARE_SETPROPERTY_OFFSET(16);
129 DECLARE_SETPROPERTY_OFFSET(20);
130 DECLARE_SETPROPERTY_OFFSET(24);
131 DECLARE_SETPROPERTY_OFFSET(28);
132 DECLARE_SETPROPERTY_OFFSET(32);
133 DECLARE_SETPROPERTY_OFFSET(36);
134 DECLARE_SETPROPERTY_OFFSET(40);
135 DECLARE_SETPROPERTY_OFFSET(44);
136 DECLARE_SETPROPERTY_OFFSET(48);
137 DECLARE_SETPROPERTY_OFFSET(52);
138 DECLARE_SETPROPERTY_OFFSET(56);
139 DECLARE_SETPROPERTY_OFFSET(60);
140 DECLARE_SETPROPERTY_OFFSET(64);
143 static void* _setProperty_offset_table
[] = {
144 SETPROPERTY_OFFSET(0),
145 SETPROPERTY_OFFSET(4),
146 SETPROPERTY_OFFSET(8),
147 SETPROPERTY_OFFSET(12),
148 SETPROPERTY_OFFSET(16),
149 SETPROPERTY_OFFSET(20),
150 SETPROPERTY_OFFSET(24),
151 SETPROPERTY_OFFSET(28),
152 SETPROPERTY_OFFSET(32),
153 SETPROPERTY_OFFSET(36),
154 SETPROPERTY_OFFSET(40),
155 SETPROPERTY_OFFSET(44),
156 SETPROPERTY_OFFSET(48),
157 SETPROPERTY_OFFSET(52),
158 SETPROPERTY_OFFSET(56),
159 SETPROPERTY_OFFSET(60),
160 SETPROPERTY_OFFSET(64),
163 #undef SETPROPERTY_OFFSET
164 #undef DECLARE_SETPROPERTY_OFFSET
165 #undef IMPLEMENT_SETPROPERTY_OFFSET
166 #define SETPROPERTY_IMP(offset) ((offset <= 64) ? (IMP)_setProperty_offset_table[offset >> 2] : NULL)