Skip to content

Commit

Permalink
Merge pull request #1101 from rust-lang/reselect-warnings
Browse files Browse the repository at this point in the history
Avoid creating new objects/arrays in selectors
  • Loading branch information
shepmaster authored Oct 4, 2024
2 parents 121537a + f866f92 commit aa97766
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions ui/frontend/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,22 @@ export const getAdvancedOptionsSet = createSelector(

export const hasProperties = (obj: {}) => Object.values(obj).some(val => !!val);

const getOutputs = (state: State) => [
state.output.assembly,
state.output.clippy,
state.output.execute,
state.output.format,
state.output.gist,
state.output.llvmIr,
state.output.mir,
state.output.hir,
state.output.miri,
state.output.macroExpansion,
state.output.wasm,
];
const getOutputs = createSelector(
(state: State) => state,
(state) => [
state.output.assembly,
state.output.clippy,
state.output.execute,
state.output.format,
state.output.gist,
state.output.llvmIr,
state.output.mir,
state.output.hir,
state.output.miri,
state.output.macroExpansion,
state.output.wasm,
],
);

export const getSomethingToShow = createSelector(
getOutputs,
Expand Down Expand Up @@ -479,7 +482,7 @@ export const executeRequestPayloadSelector = createSelector(
channelSelector,
(state: State) => state.configuration,
getBacktraceSet,
(_state: State, { crateType, tests }: { crateType: string, tests: boolean }) => ({ crateType, tests }),
(_state: State, args: { crateType: string, tests: boolean }) => args,
(code, channel, configuration, backtrace, { crateType, tests }) => ({
channel,
mode: configuration.mode,
Expand All @@ -498,7 +501,7 @@ export const compileRequestPayloadSelector = createSelector(
getCrateType,
runAsTest,
getBacktraceSet,
(_state: State, { target }: { target: string }) => ({ target }),
(_state: State, args: { target: string }) => args,
(code, channel, configuration, crateType, tests, backtrace, { target }) => ({
channel,
mode: configuration.mode,
Expand Down

0 comments on commit aa97766

Please sign in to comment.