You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
789 B
30 lines
789 B
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* 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(int x) {
|
|
for (int i = 0; i < x; 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(int b) {
|
|
for (int i = 0; i < b; i++) {
|
|
timing_calls_dont_hoist(b); // don't hoist
|
|
harmless_pure(); // ok to hoist
|
|
}
|
|
}
|
|
}
|