<commit_before>import { ViewData } from './types';

export function attachEmbeddedView(parentView: ViewData, viewIndex: number, view: ViewData) {
  // let embeddedViews = parentView.embeddedViews;
  // if (viewIndex == null) {
  //   viewIndex = embeddedViews.length;
  // }
  // view.viewContainerParent = parentView;
  // addToArray(embeddedViews, viewIndex, view);
}

export function detachEmbeddedView(parent: ViewData, viewIndex: number): ViewData {
  // const embeddedViews = parent.embeddedViews;
  // if (viewIndex == null || viewIndex >= embeddedViews.length) {
  //   viewIndex = embeddedViews.length - 1;
  // }
  // if (viewIndex < 0) {
  //   return null;
  // }
  // const view = embeddedViews[viewIndex];
  // view.viewContainerParent = undefined;
  // removeFromArray(embeddedViews, viewIndex);
  // return view;
  return null;
}

function addToArray(arr: any[], index: number, value: any) {
  // perf: array.push is faster than array.splice!
  if (index >= arr.length) {
    arr.push(value);
  } else {
    arr.splice(index, 0, value);
  }
}

function removeFromArray(arr: any[], index: number) {
  // perf: array.pop is faster than array.splice!
  if (index >= arr.length - 1) {
    arr.pop();
  } else {
    arr.splice(index, 1);
  }
}<commit_msg>view attach<commit_after>import { ViewData } from './types';

export function attachEmbeddedView(parentView: ViewData, viewIndex: number, view: ViewData) {
  let embeddedViews = parentView.embeddedViews;
  if (viewIndex == null) {
    viewIndex = embeddedViews.length;
  }
  view.viewContainerParent = parentView;
  addToArray(embeddedViews, viewIndex, view);
}

export function detachEmbeddedView(parent: ViewData, viewIndex: number): ViewData {
  const embeddedViews = parent.embeddedViews;
  if (viewIndex == null || viewIndex >= embeddedViews.length) {
    viewIndex = embeddedViews.length - 1;
  }
  if (viewIndex < 0) {
    return null;
  }
  const view = embeddedViews[viewIndex];
  view.viewContainerParent = undefined;
  removeFromArray(embeddedViews, viewIndex);
  return view;
}

function addToArray(arr: any[], index: number, value: any) {
  // perf: array.push is faster than array.splice!
  if (index >= arr.length) {
    arr.push(value);
  } else {
    arr.splice(index, 0, value);
  }
}

function removeFromArray(arr: any[], index: number) {
  // perf: array.pop is faster than array.splice!
  if (index >= arr.length - 1) {
    arr.pop();
  } else {
    arr.splice(index, 1);
  }
}
{'fraction_non_alphanumeric': 0.13839285714285715, 'fraction_numerical': 0.004058441558441558, 'mean_word_length': 3.607476635514019, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5433136', 'n_tokens_mistral': 809, 'n_tokens_neox': 787, 'n_words': 197}