mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Auto merge of #18393 - servo:get-property-value-unsafe, r=emilio
Make get_property_value unsafe This takes raw pointers and does things with the things they point to, and circumvent a lock on a hash table. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18393) <!-- Reviewable:end -->
This commit is contained in:
commit
5defc56ad5
1 changed files with 77 additions and 36 deletions
|
@ -2301,7 +2301,7 @@ pub extern "C" fn Servo_DeclarationBlock_GetNthProperty(declarations: RawServoDe
|
||||||
|
|
||||||
macro_rules! get_property_id_from_property {
|
macro_rules! get_property_id_from_property {
|
||||||
($property: ident, $ret: expr) => {{
|
($property: ident, $ret: expr) => {{
|
||||||
let property = unsafe { $property.as_ref().unwrap().as_str_unchecked() };
|
let property = $property.as_ref().unwrap().as_str_unchecked();
|
||||||
match PropertyId::parse(property.into(), None) {
|
match PropertyId::parse(property.into(), None) {
|
||||||
Ok(property_id) => property_id,
|
Ok(property_id) => property_id,
|
||||||
Err(_) => { return $ret; }
|
Err(_) => { return $ret; }
|
||||||
|
@ -2309,33 +2309,46 @@ macro_rules! get_property_id_from_property {
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_property_value(declarations: RawServoDeclarationBlockBorrowed,
|
unsafe fn get_property_value(
|
||||||
property_id: PropertyId, value: *mut nsAString) {
|
declarations: RawServoDeclarationBlockBorrowed,
|
||||||
|
property_id: PropertyId,
|
||||||
|
value: *mut nsAString,
|
||||||
|
) {
|
||||||
// This callsite is hot enough that the lock acquisition shows up in profiles.
|
// This callsite is hot enough that the lock acquisition shows up in profiles.
|
||||||
// Using an unchecked read here improves our performance by ~10% on the
|
// Using an unchecked read here improves our performance by ~10% on the
|
||||||
// microbenchmark in bug 1355599.
|
// microbenchmark in bug 1355599.
|
||||||
unsafe {
|
|
||||||
read_locked_arc_unchecked(declarations, |decls: &PropertyDeclarationBlock| {
|
read_locked_arc_unchecked(declarations, |decls: &PropertyDeclarationBlock| {
|
||||||
decls.property_value_to_css(&property_id, value.as_mut().unwrap()).unwrap();
|
decls.property_value_to_css(&property_id, value.as_mut().unwrap()).unwrap();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn Servo_DeclarationBlock_GetPropertyValue(
|
||||||
|
declarations: RawServoDeclarationBlockBorrowed,
|
||||||
|
property: *const nsACString,
|
||||||
|
value: *mut nsAString,
|
||||||
|
) {
|
||||||
|
get_property_value(
|
||||||
|
declarations,
|
||||||
|
get_property_id_from_property!(property, ()),
|
||||||
|
value,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_DeclarationBlock_GetPropertyValue(declarations: RawServoDeclarationBlockBorrowed,
|
pub unsafe extern "C" fn Servo_DeclarationBlock_GetPropertyValueById(
|
||||||
property: *const nsACString, value: *mut nsAString) {
|
declarations: RawServoDeclarationBlockBorrowed,
|
||||||
get_property_value(declarations, get_property_id_from_property!(property, ()), value)
|
property: nsCSSPropertyID,
|
||||||
}
|
value: *mut nsAString,
|
||||||
|
) {
|
||||||
#[no_mangle]
|
|
||||||
pub extern "C" fn Servo_DeclarationBlock_GetPropertyValueById(declarations: RawServoDeclarationBlockBorrowed,
|
|
||||||
property: nsCSSPropertyID, value: *mut nsAString) {
|
|
||||||
get_property_value(declarations, get_property_id_from_nscsspropertyid!(property, ()), value)
|
get_property_value(declarations, get_property_id_from_nscsspropertyid!(property, ()), value)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_DeclarationBlock_GetPropertyIsImportant(declarations: RawServoDeclarationBlockBorrowed,
|
pub unsafe extern "C" fn Servo_DeclarationBlock_GetPropertyIsImportant(
|
||||||
property: *const nsACString) -> bool {
|
declarations: RawServoDeclarationBlockBorrowed,
|
||||||
|
property: *const nsACString,
|
||||||
|
) -> bool {
|
||||||
let property_id = get_property_id_from_property!(property, false);
|
let property_id = get_property_id_from_property!(property, false);
|
||||||
read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| {
|
read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| {
|
||||||
decls.property_priority(&property_id).important()
|
decls.property_priority(&property_id).important()
|
||||||
|
@ -2362,25 +2375,49 @@ fn set_property(declarations: RawServoDeclarationBlockBorrowed, property_id: Pro
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_DeclarationBlock_SetProperty(declarations: RawServoDeclarationBlockBorrowed,
|
pub unsafe extern "C" fn Servo_DeclarationBlock_SetProperty(
|
||||||
property: *const nsACString, value: *const nsACString,
|
declarations: RawServoDeclarationBlockBorrowed,
|
||||||
is_important: bool, data: *mut URLExtraData,
|
property: *const nsACString,
|
||||||
|
value: *const nsACString,
|
||||||
|
is_important: bool,
|
||||||
|
data: *mut URLExtraData,
|
||||||
parsing_mode: structs::ParsingMode,
|
parsing_mode: structs::ParsingMode,
|
||||||
quirks_mode: nsCompatibility,
|
quirks_mode: nsCompatibility,
|
||||||
loader: *mut Loader) -> bool {
|
loader: *mut Loader,
|
||||||
set_property(declarations, get_property_id_from_property!(property, false),
|
) -> bool {
|
||||||
value, is_important, data, parsing_mode, quirks_mode.into(), loader)
|
set_property(
|
||||||
|
declarations,
|
||||||
|
get_property_id_from_property!(property, false),
|
||||||
|
value,
|
||||||
|
is_important,
|
||||||
|
data,
|
||||||
|
parsing_mode,
|
||||||
|
quirks_mode.into(),
|
||||||
|
loader,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_DeclarationBlock_SetPropertyById(declarations: RawServoDeclarationBlockBorrowed,
|
pub unsafe extern "C" fn Servo_DeclarationBlock_SetPropertyById(
|
||||||
property: nsCSSPropertyID, value: *const nsACString,
|
declarations: RawServoDeclarationBlockBorrowed,
|
||||||
is_important: bool, data: *mut URLExtraData,
|
property: nsCSSPropertyID,
|
||||||
|
value: *const nsACString,
|
||||||
|
is_important: bool,
|
||||||
|
data: *mut URLExtraData,
|
||||||
parsing_mode: structs::ParsingMode,
|
parsing_mode: structs::ParsingMode,
|
||||||
quirks_mode: nsCompatibility,
|
quirks_mode: nsCompatibility,
|
||||||
loader: *mut Loader) -> bool {
|
loader: *mut Loader,
|
||||||
set_property(declarations, get_property_id_from_nscsspropertyid!(property, false),
|
) -> bool {
|
||||||
value, is_important, data, parsing_mode, quirks_mode.into(), loader)
|
set_property(
|
||||||
|
declarations,
|
||||||
|
get_property_id_from_nscsspropertyid!(property, false),
|
||||||
|
value,
|
||||||
|
is_important,
|
||||||
|
data,
|
||||||
|
parsing_mode,
|
||||||
|
quirks_mode.into(),
|
||||||
|
loader,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_property(declarations: RawServoDeclarationBlockBorrowed, property_id: PropertyId) {
|
fn remove_property(declarations: RawServoDeclarationBlockBorrowed, property_id: PropertyId) {
|
||||||
|
@ -2390,8 +2427,10 @@ fn remove_property(declarations: RawServoDeclarationBlockBorrowed, property_id:
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_DeclarationBlock_RemoveProperty(declarations: RawServoDeclarationBlockBorrowed,
|
pub unsafe extern "C" fn Servo_DeclarationBlock_RemoveProperty(
|
||||||
property: *const nsACString) {
|
declarations: RawServoDeclarationBlockBorrowed,
|
||||||
|
property: *const nsACString,
|
||||||
|
) {
|
||||||
remove_property(declarations, get_property_id_from_property!(property, ()))
|
remove_property(declarations, get_property_id_from_property!(property, ()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2887,8 +2926,10 @@ pub extern "C" fn Servo_DeclarationBlock_SetTextDecorationColorOverride(declarat
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_CSSSupports2(property: *const nsACString,
|
pub unsafe extern "C" fn Servo_CSSSupports2(
|
||||||
value: *const nsACString) -> bool {
|
property: *const nsACString,
|
||||||
|
value: *const nsACString,
|
||||||
|
) -> bool {
|
||||||
let id = get_property_id_from_property!(property, false);
|
let id = get_property_id_from_property!(property, false);
|
||||||
|
|
||||||
let mut declarations = SourcePropertyDeclaration::new();
|
let mut declarations = SourcePropertyDeclaration::new();
|
||||||
|
@ -2896,7 +2937,7 @@ pub extern "C" fn Servo_CSSSupports2(property: *const nsACString,
|
||||||
&mut declarations,
|
&mut declarations,
|
||||||
id,
|
id,
|
||||||
value,
|
value,
|
||||||
unsafe { DUMMY_URL_DATA },
|
DUMMY_URL_DATA,
|
||||||
structs::ParsingMode_Default,
|
structs::ParsingMode_Default,
|
||||||
QuirksMode::NoQuirks,
|
QuirksMode::NoQuirks,
|
||||||
&NullReporter,
|
&NullReporter,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue