Reviewed By: mbouaziz Differential Revision: D13941653 fbshipit-source-id: 02a15b29cmaster
parent
d08cabe7ed
commit
6e0682b463
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2019-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
class HoistUnmodeled {
|
||||
|
||||
// Any unmodeled (e.g. timing) call is assumed to be modifying global
|
||||
// state
|
||||
void timing_calls_dont_hoist() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.nanoTime();
|
||||
}
|
||||
}
|
||||
|
||||
// doesn't read from global state or call any unmodeled function, a
|
||||
// harmless pure function
|
||||
void harmless_pure() {}
|
||||
|
||||
// It should be ok to hoist harmless_pure() since it doesn't read
|
||||
// from global state.
|
||||
void harmless_hoist_FN() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
timing_calls_dont_hoist(); // don't hoist
|
||||
harmless_pure(); // ok to hoist
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue