<commit_before>/**
 * 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.
 *
 * @flow
 */

import type {PriorityLevel} from './SchedulerPriorities';
import {enableProfiling} from './SchedulerFeatureFlags';

import {NoPriority} from './SchedulerPriorities';

let runIdCounter: number = 0;
let mainThreadIdCounter: number = 0;

const profilingStateSize = 4;
export const sharedProfilingBuffer = enableProfiling
  ? // $FlowFixMe Flow doesn't know about SharedArrayBuffer
    typeof SharedArrayBuffer === 'function'
    ? new SharedArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT)
    : // $FlowFixMe Flow doesn't know about ArrayBuffer
    typeof ArrayBuffer === 'function'
    ? new ArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT)
    : null // Don't crash the init path on IE9
  : null;

const profilingState =
  enableProfiling && sharedProfilingBuffer !== null
    ? new Int32Array(sharedProfilingBuffer)
    : []; // We can't read this but it helps save bytes for null checks

const PRIORITY = 0;
const CURRENT_TASK_ID = 1;
const CURRENT_RUN_ID = 2;
const QUEUE_SIZE = 3;

if (enableProfiling) {
  profilingState[PRIORITY] = NoPriority;
  // This is maintained with a counter, because the size of the priority queue
  // array might include canceled tasks.
  profilingState[QUEUE_SIZE] = 0;
  profilingState[CURRENT_TASK_ID] = 0;
}

// Bytes per element is 4<commit_msg>fix: use SharedArrayBuffer only when cross-origin isolation is enabled (#20831)<commit_after>/**
 * 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.
 *
 * @flow
 */

import type {PriorityLevel} from './SchedulerPriorities';
import {enableProfiling} from './SchedulerFeatureFlags';

import {NoPriority} from './SchedulerPriorities';

let runIdCounter: number = 0;
let mainThreadIdCounter: number = 0;

const isEnabledSharedArrayBuffer =
  // $FlowFixMe Flow doesn't know about SharedArrayBuffer
  typeof SharedArrayBuffer === 'function' &&
  // We only use SharedArrayBuffer when cross origin isolation is enabled.
  typeof window !== 'undefined' &&
  window.crossOriginIsolated === true;

const profilingStateSize = 4;
export const sharedProfilingBuffer = enableProfiling
  ? isEnabledSharedArrayBuffer
    ? new SharedArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT)
    : typeof ArrayBuffer === 'function'
    ? new ArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT)
    : null // Don't crash the init path on IE9
  : null;

const profilingState =
  enableProfiling && sharedProfilingBuffer !== null
    ? new Int32Array(sharedProfilingBuffer)
    : []; // We can't read this but it helps save bytes for null checks

const PRIORITY = 0;
const CURRENT_TASK_ID = 1;
const CURRENT_RUN_ID = 2;
const QUEUE_SIZE = 3;

if (enableProfiling) {
  profilingState[PRIORITY] = NoPriority;
  // This is maintained with a counter, because the size of the priority queue
  // array might include canceled tasks.
  profilingState[QUEUE_SIZE] = 0;
  profilingState[CURRENT_TASK_ID] = 0;
}

// Bytes per element is 4
{'fraction_non_alphanumeric': 0.08802924154736522, 'fraction_numerical': 0.01187937861711849, 'mean_word_length': 4.410214168039539, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '243220', 'n_tokens_mistral': 1025, 'n_tokens_neox': 941, 'n_words': 328}