ronantakizawa/codereview-bench huggingface dataset:
Repository: MystenLabs/sui
File: sui-execution/cut/src/path.rs (Rust)

Code before:

    Ok(stack.iter().collect())
}

/// Return the path to `dst` relative to `src`.  If `src` is a file, the path is relative to the
/// directory that contains it, while if it is a directory, the path is relative to it.  Returns
/// an error if either `src` or `dst` do not exist.
pub(crate) fn path_relative_to<P, Q>(src: P, dst: Q) -> io::Result<PathBuf>
where
    P: AsRef<Path>,
    Q: AsRef<Path>,
{
    use std::path::Component as C;

    let mut src = fs::canonicalize(src)?;
    let dst = fs::canonicalize(dst)?;

    if src.is_file() {
        src.pop();
    }

    let mut s_comps = src.components().peekable();
    let mut d_comps = dst.components().peekable();

    // (1). Strip matching prefix
    loop {
        let Some(s_comp) = s_comps.peek() else { break };
        let Some(d_comp) = d_comps.peek() else { break };
        if s_comp != d_comp {
            break;
        }

        s_comps.next();
        d_comps.next();
    }

    // (2) Push parent directory components (moving out of directories in `base`)
    let mut stack = vec![];
    for _ in s_comps {
        stack.push(C::ParentDir)
    }

    // (3) Push extension directory components (moving into directories unique to `ext`)
    for comp in d_comps {
        stack.push(comp)
    }

    // (4) Check for base == ext case
    if stack.is_empty() {
        stack.push(C::CurDir)
    }

Review comment (suggestion):
Complained that this loop can be a while, so this seems to be fine because both `s_comp` and `d_comp` are defined as `mut` above.

Code after:

    Ok(stack.iter().collect())
}

/// Return the path to `dst` relative to `src`.  If `src` is a file, the path is relative to the
/// directory that contains it, while if it is a directory, the path is relative to it.  Returns
/// an error if either `src` or `dst` do not exist.
pub(crate) fn path_relative_to<P, Q>(src: P, dst: Q) -> io::Result<PathBuf>
where
    P: AsRef<Path>,
    Q: AsRef<Path>,
{
    use std::path::Component as C;

    let mut src = fs::canonicalize(src)?;
    let dst = fs::canonicalize(dst)?;

    if src.is_file() {
        src.pop();
    }

    let mut s_comps = src.components().peekable();
    let mut d_comps = dst.components().peekable();

    // (1). Strip matching prefix
    while let (Some(s_comp), Some(d_comp)) = (s_comps.peek(), d_comps.peek()) {
        if s_comp != d_comp {
            break;
        }
        s_comps.next();
        d_comps.next();
    }
    // (2) Push parent directory components (moving out of directories in `base`)
    let mut stack = vec![];
    for _ in s_comps {
        stack.push(C::ParentDir)
    }

    // (3) Push extension directory components (moving into directories unique to `ext`)
    for comp in d_comps {
        stack.push(comp)
    }

    // (4) Check for base == ext case
    if stack.is_empty() {
        stack.push(C::CurDir)
    }

    Ok(stack.into_iter().collect())
}
Repository: MystenLabs/sui
File: crates/sui-indexer-alt-graphql/src/extensions/timeout.rs (Rust)

Code before:
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
use std::sync::{Arc, OnceLock};
use std::time::Duration;

use crate::error::request_timeout;
use crate::extensions::logging::Session;
use async_graphql::ServerError;
use async_graphql::ServerResult;
use async_graphql::Variables;
use async_graphql::extensions::ExtensionContext;
use async_graphql::extensions::ExtensionFactory;
use async_graphql::extensions::NextExecute;
use async_graphql::extensions::NextParseQuery;
use async_graphql::extensions::{Extension, NextPrepareRequest};
use async_graphql::parser::types::ExecutableDocument;
use async_graphql::parser::types::OperationType;
use async_graphql::{Request, Response};
use timeout_tracing::CaptureSpanTrace;
use timeout_tracing::timeout;
use tracing::warn;

/// How long to wait for each kind of operation before timing out.
pub(crate) struct TimeoutConfig {
    pub(crate) query: Duration,
    pub(crate) mutation: Duration,
}


Review comment (suggestion):
nit: one import per line please. I think this may be a Rust Rover specific issue as `rust-analyzer` will typically follow the convention in the file. Maybe there's a setting you can change so that Rust Rover will do the same.

Code after:
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use std::sync::Arc;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
use std::time::Duration;

use async_graphql::Response;
use async_graphql::ServerError;
use async_graphql::ServerResult;
use async_graphql::Variables;
use async_graphql::extensions::Extension;
use async_graphql::extensions::ExtensionContext;
use async_graphql::extensions::ExtensionFactory;
use async_graphql::extensions::NextExecute;
use async_graphql::extensions::NextParseQuery;
use async_graphql::parser::types::ExecutableDocument;
use async_graphql::parser::types::OperationType;
use timeout_tracing::CaptureSpanTrace;
use timeout_tracing::timeout;
use tracing::warn;

use crate::error::request_timeout;
use crate::extensions::logging::Session;

/// How long to wait for each kind of operation before timing out.
pub(crate) struct TimeoutConfig {
    pub(crate) query: Duration,
    pub(crate) mutation: Duration,
}
Repository: MystenLabs/sui
File: external-crates/move/crates/move-compiler/src/hlir/translate.rs (Rust)

Code before:
    }
}

fn make_assignments(
    context: &mut Context,
    result: &mut Block,
    loc: Loc,
    case: H::AssignCase,
    sp!(_, assigns): T::LValueList,
    rvalue: H::Exp,
) {
    use H::{Command_ as C, Statement_ as S};
    let mut lvalues = vec![];
    let mut after = Block::new();
    for (idx, a) in assigns.into_iter().enumerate() {
        let error_ty;
        let a_ty = match rvalue.ty.value.type_at_index(idx) {
            Some(ty) => ty,
            None => {
                // we can only get here if the rvalue was malformed and somewhere has an unresolved
                // error
                debug_assert!(context.env.has_errors());
                error_ty = error_single_type(a.loc);
                &error_ty
            }
        };
        let (ls, mut af) = assign(context, case, a, a_ty);

        lvalues.push(ls);
        after.append(&mut af);
    }
    result.push_back(sp(
        loc,
        S::Command(sp(loc, C::Assign(case, lvalues, rvalue))),
    ));
    result.append(&mut after);
}

fn assign(
    context: &mut Context,
    case: H::AssignCase,
    sp!(loc, ta_): T::LValue,
    rvalue_ty: &H::SingleType,
) -> (H::LValue, Block) {
    use H::{LValue_ as L, UnannotatedExp_ as E};
    use T::LValue_ as A;
    let mut after = Block::new();
    let l_ = match ta_ {
        A::Ignore => L::Ignore,
        A::Var {
            var: v,

Review comment (suggestion):
This seemed like the easiest fix, and maybe the best fix? 
Otherwise we would have to a lot of massaging for `make_binders` and `bind_value_in_block`. And since we must already be in an error, might as well keep propagating 

Code after:
    }
}

fn make_assignments(
    context: &mut Context,
    result: &mut Block,
    loc: Loc,
    case: H::AssignCase,
    sp!(_, assigns): T::LValueList,
    rvalue: H::Exp,
) {
    use H::{Command_ as C, Statement_ as S};
    let mut lvalues = vec![];
    let mut after = Block::new();
    for (idx, a) in assigns.into_iter().enumerate() {
        let error_ty = error_single_type(a.loc);
        let a_ty = rvalue.ty.value.type_at_index(idx).unwrap_or_else(|| {
            // we can only get here if the rvalue was malformed and somewhere has an unresolved
            // erro
            ice_assert!(
                context,
                context.env.has_errors(),
                a.loc,
                "Unable to find a type for assignment lvalue from the rvalue"
            );
            &error_ty
        });
        let (ls, mut af) = assign(context, case, a, a_ty);

        lvalues.push(ls);
        after.append(&mut af);
    }
    result.push_back(sp(
        loc,
        S::Command(sp(loc, C::Assign(case, lvalues, rvalue))),
    ));
    result.append(&mut after);
}

fn assign(
    context: &mut Context,
    case: H::AssignCase,
    sp!(loc, ta_): T::LValue,
    rvalue_ty: &H::SingleType,
) -> (H::LValue, Block) {
    use H::{LValue_ as L, UnannotatedExp_ as E};
    use T::LValue_ as A;
    let mut after = Block::new();
    let l_ = match ta_ {
        A::Ignore => L::Ignore,
        A::Var {
Repository: NativeScript/NativeScript
File: packages/core/data/observable-array/index.ts (TypeScript)

Code before:
		this._array[index] = value;

		this.notify(<ChangedData<T>>{
			eventName: CHANGE,
			object: this,
			action: ChangeType.Update,
			index: index,
			removed: [oldValue],
			addedCount: 1,
		});
	}

	/**
	 * Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
	 */
	get length(): number {
		return this._array.length;
	}

	set length(value: number) {
		if (types.isNumber(value) && this._array && this._array.length !== value) {
			this.splice(value, this._array.length - value);
		}
	}

	/**
	 * Returns a string representation of an array.
	 */
	toString(): string {
		return this._array.toString();
	}

	toLocaleString(): string {
		return this._array.toLocaleString();
	}

	/**
	 * Combines two or more arrays.
	 * @param items Additional items to add to the end of array1.
	 */
	concat(_args?: any): T[] {
		this._addArgs.index = this._array.length;
		const result = this._array.concat.apply(this._array, arguments);

		return result;
	}

	/**
	 * Adds all the elements of an array separated by the specified separator string.
	 * @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
	 */

Review comment (suggestion):
Would this be cleaner/faster? (According to a quick benchmark, it is 50% faster, but I don't trust benchmarks that much)

```suggestion
			let added = Array(Math.max(value - this._array.length, 0)).fill(undefined);
```

Code after:
		let oldValue = this._array[index];
		this._array[index] = value;

		this.notify(<ChangedData<T>>{
			eventName: CHANGE,
			object: this,
			action: ChangeType.Update,
			index: index,
			removed: [oldValue],
			addedCount: 1,
		});
	}

	/**
	 * Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
	 */
	get length(): number {
		return this._array.length;
	}

	set length(value: number) {
		if (types.isNumber(value) && this._array && this._array.length !== value) {
			let added=[];
			for (let i=this._array.length;i < value;++i) {
				added.push(undefined);
			}
			this.splice(value, this._array.length - value, ...added);
		}
	}

	/**
	 * Returns a string representation of an array.
	 */
	toString(): string {
		return this._array.toString();
	}

	toLocaleString(): string {
		return this._array.toLocaleString();
	}

	/**
	 * Combines two or more arrays.
	 * @param items Additional items to add to the end of array1.
	 */
	concat(_args?: any): T[] {
		this._addArgs.index = this._array.length;
		const result = this._array.concat.apply(this._array, arguments);

		return result;
	}
Repository: NativeScript/NativeScript
File: packages/core/ui/core/view-base/index.ts (TypeScript)

Code before:
				if (property === 'bindingContext') {
					this.shouldAddHandlerToParentBindingContextChanged = false;
					this.bindingContextBoundToParentBindingContextChanged = false;
					const parent = this.parent;
					if (parent) {
						parent.off('bindingContextChange', this.bindingContextChanged, this);
					}
				}
			}
		}
	}

	private performLayout(currentRun = 0) {
		// if there's an animation in progress we need to delay the layout
		// we've added a guard of 5000 milliseconds execution
		// to make sure that the layout will happen even if the animation haven't finished in 5 seconds
		if (this._shouldDelayLayout() && currentRun < 100) {
			setTimeout(() => this.performLayout(currentRun), currentRun);
			currentRun++;
		} else {
			this.parent.requestLayout();
		}
	}


	_requetLayoutNeeded = false;

	get isLayoutRequestNeeded() {
		return this._requetLayoutNeeded;
	}
	
	_suspendRequestLayout = false;
	set suspendRequestLayout(value: boolean) {
		this._suspendRequestLayout = value;
	}
	get suspendRequestLayout() {
		return this._suspendRequestLayout;
	}

	@profile
	public requestLayout(): void {

		// Default implementation for non View instances (like TabViewItem).
		const parent = this.parent;
		if (parent) {
			this.performLayout();
		}
	}

	public eachChild(callback: (child: ViewBase) => boolean) {
		//

Review comment (suggestion):
@farfromrefug Could you just fix the spelling here:

```suggestion
	_requestLayoutNeeded = false;
```

Code after:
		const targetProperty = options.targetProperty;
		this.unbind(targetProperty);

		if (!this.bindings) {
			this.bindings = new Map<string, Binding>();
		}

		const binding = new Binding(this, options);
		this.bindings.set(targetProperty, binding);

		let bindingSource = source;
		if (bindingSource === defaultBindingSource) {
			bindingSource = this.bindingContext;
			binding.sourceIsBindingContext = true;
			if (targetProperty === 'bindingContext') {
				this.bindingContextBoundToParentBindingContextChanged = true;
				const parent = this.parent;
				if (parent) {
					parent.on('bindingContextChange', this.bindingContextChanged, this);
				} else {
					this.shouldAddHandlerToParentBindingContextChanged = true;
				}
			}
		}

		binding.bind(bindingSource);
	}

	public unbind(property: string): void {
		const bindings = this.bindings;
		if (!bindings) {
			return;
		}

		const binding = bindings.get(property);
		if (binding) {
			binding.unbind();
			bindings.delete(property);
			if (binding.sourceIsBindingContext) {
				if (property === 'bindingContext') {
					this.shouldAddHandlerToParentBindingContextChanged = false;
					this.bindingContextBoundToParentBindingContextChanged = false;
					const parent = this.parent;
					if (parent) {
						parent.off('bindingContextChange', this.bindingContextChanged, this);
					}
				}
			}
		}
	}
Repository: NativeScript/NativeScript
File: packages/core/ui/core/view/index.android.ts (TypeScript)

Code before:
	get isLayoutRequired(): boolean {
		return !this.isLayoutValid;
	}

	get isLayoutValid(): boolean {
		if (this.nativeViewProtected) {
			return !this.nativeViewProtected.isLayoutRequested();
		}

		return false;
	}

	get _hasFragments(): boolean {
		return false;
	}

	public layoutNativeView(left: number, top: number, right: number, bottom: number): void {
		if (this.nativeViewProtected) {
			this.nativeViewProtected.layout(left, top, right, bottom);
		}
	}

	@profile
	public requestLayout(): void {
		if (this._suspendRequestLayout) {
			this._requetLayoutNeeded = true;
			return;
		}
		this._requetLayoutNeeded = false;
		super.requestLayout();
		if (this.nativeViewProtected) {
			this.nativeViewProtected.requestLayout();
		}
	}

	public measure(widthMeasureSpec: number, heightMeasureSpec: number): void {
		super.measure(widthMeasureSpec, heightMeasureSpec);
		this.onMeasure(widthMeasureSpec, heightMeasureSpec);
	}

	public layout(left: number, top: number, right: number, bottom: number): void {
		super.layout(left, top, right, bottom);
		this.onLayout(left, top, right, bottom);
	}

	public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
		const view = this.nativeViewProtected;
		if (view) {
			view.measure(widthMeasureSpec, heightMeasureSpec);
			this.setMeasuredDimension(view.getMeasuredWidth(), view.getMeasuredHeight());
		}

Review comment (suggestion):
```suggestion
			this._requestLayoutNeeded = true;
```

Code after:

	get isLayoutValid(): boolean {
		if (this.nativeViewProtected) {
			return !this.nativeViewProtected.isLayoutRequested();
		}

		return false;
	}

	get _hasFragments(): boolean {
		return false;
	}

	public layoutNativeView(left: number, top: number, right: number, bottom: number): void {
		if (this.nativeViewProtected) {
			this.nativeViewProtected.layout(left, top, right, bottom);
		}
	}

	@profile
	public requestLayout(): void {
		if (this._suspendRequestLayout) {
			this._requestLayoutNeeded = true;
			return;
		}
		this._requestLayoutNeeded = false;
		super.requestLayout();
		if (this.nativeViewProtected) {
			this.nativeViewProtected.requestLayout();
		}
	}

	public measure(widthMeasureSpec: number, heightMeasureSpec: number): void {
		super.measure(widthMeasureSpec, heightMeasureSpec);
		this.onMeasure(widthMeasureSpec, heightMeasureSpec);
	}

	public layout(left: number, top: number, right: number, bottom: number): void {
		super.layout(left, top, right, bottom);
		this.onLayout(left, top, right, bottom);
	}

	public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
		const view = this.nativeViewProtected;
		if (view) {
			view.measure(widthMeasureSpec, heightMeasureSpec);
			this.setMeasuredDimension(view.getMeasuredWidth(), view.getMeasuredHeight());
		}
	}

	public onLayout(left: number, top: number, right: number, bottom: number): void {
Repository: NativeScript/NativeScript
File: packages/core/ui/core/view/index.android.ts (TypeScript)

Code before:

	get isLayoutValid(): boolean {
		if (this.nativeViewProtected) {
			return !this.nativeViewProtected.isLayoutRequested();
		}

		return false;
	}

	get _hasFragments(): boolean {
		return false;
	}

	public layoutNativeView(left: number, top: number, right: number, bottom: number): void {
		if (this.nativeViewProtected) {
			this.nativeViewProtected.layout(left, top, right, bottom);
		}
	}

	@profile
	public requestLayout(): void {
		if (this._suspendRequestLayout) {
			this._requetLayoutNeeded = true;
			return;
		}
		this._requetLayoutNeeded = false;
		super.requestLayout();
		if (this.nativeViewProtected) {
			this.nativeViewProtected.requestLayout();
		}
	}

	public measure(widthMeasureSpec: number, heightMeasureSpec: number): void {
		super.measure(widthMeasureSpec, heightMeasureSpec);
		this.onMeasure(widthMeasureSpec, heightMeasureSpec);
	}

	public layout(left: number, top: number, right: number, bottom: number): void {
		super.layout(left, top, right, bottom);
		this.onLayout(left, top, right, bottom);
	}

	public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
		const view = this.nativeViewProtected;
		if (view) {
			view.measure(widthMeasureSpec, heightMeasureSpec);
			this.setMeasuredDimension(view.getMeasuredWidth(), view.getMeasuredHeight());
		}
	}

	public onLayout(left: number, top: number, right: number, bottom: number): void {

Review comment (suggestion):
```suggestion
		this._requestLayoutNeeded = false;
```

Code after:
			return !this.nativeViewProtected.isLayoutRequested();
		}

		return false;
	}

	get _hasFragments(): boolean {
		return false;
	}

	public layoutNativeView(left: number, top: number, right: number, bottom: number): void {
		if (this.nativeViewProtected) {
			this.nativeViewProtected.layout(left, top, right, bottom);
		}
	}

	@profile
	public requestLayout(): void {
		if (this._suspendRequestLayout) {
			this._requestLayoutNeeded = true;
			return;
		}
		this._requestLayoutNeeded = false;
		super.requestLayout();
		if (this.nativeViewProtected) {
			this.nativeViewProtected.requestLayout();
		}
	}

	public measure(widthMeasureSpec: number, heightMeasureSpec: number): void {
		super.measure(widthMeasureSpec, heightMeasureSpec);
		this.onMeasure(widthMeasureSpec, heightMeasureSpec);
	}

	public layout(left: number, top: number, right: number, bottom: number): void {
		super.layout(left, top, right, bottom);
		this.onLayout(left, top, right, bottom);
	}

	public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
		const view = this.nativeViewProtected;
		if (view) {
			view.measure(widthMeasureSpec, heightMeasureSpec);
			this.setMeasuredDimension(view.getMeasuredWidth(), view.getMeasuredHeight());
		}
	}

	public onLayout(left: number, top: number, right: number, bottom: number): void {
		const view = this.nativeViewProtected;
		if (view) {
			this.layoutNativeView(left, top, right, bottom);
Repository: NativeScript/NativeScript
File: packages/core/ui/core/view-base/index.ts (TypeScript)

Code before:
					const parent = this.parent;
					if (parent) {
						parent.off('bindingContextChange', this.bindingContextChanged, this);
					}
				}
			}
		}
	}

	private performLayout(currentRun = 0) {
		// if there's an animation in progress we need to delay the layout
		// we've added a guard of 5000 milliseconds execution
		// to make sure that the layout will happen even if the animation haven't finished in 5 seconds
		if (this._shouldDelayLayout() && currentRun < 100) {
			setTimeout(() => this.performLayout(currentRun), currentRun);
			currentRun++;
		} else {
			this.parent.requestLayout();
		}
	}


	_requetLayoutNeeded = false;

	get isLayoutRequestNeeded() {
		return this._requetLayoutNeeded;
	}
	
	_suspendRequestLayout = false;
	set suspendRequestLayout(value: boolean) {
		this._suspendRequestLayout = value;
	}
	get suspendRequestLayout() {
		return this._suspendRequestLayout;
	}

	@profile
	public requestLayout(): void {

		// Default implementation for non View instances (like TabViewItem).
		const parent = this.parent;
		if (parent) {
			this.performLayout();
		}
	}

	public eachChild(callback: (child: ViewBase) => boolean) {
		//
	}

	@profile

Review comment (suggestion):
```suggestion
		return this._requestLayoutNeeded;
```

Code after:
		if (!this.bindings) {
			this.bindings = new Map<string, Binding>();
		}

		const binding = new Binding(this, options);
		this.bindings.set(targetProperty, binding);

		let bindingSource = source;
		if (bindingSource === defaultBindingSource) {
			bindingSource = this.bindingContext;
			binding.sourceIsBindingContext = true;
			if (targetProperty === 'bindingContext') {
				this.bindingContextBoundToParentBindingContextChanged = true;
				const parent = this.parent;
				if (parent) {
					parent.on('bindingContextChange', this.bindingContextChanged, this);
				} else {
					this.shouldAddHandlerToParentBindingContextChanged = true;
				}
			}
		}

		binding.bind(bindingSource);
	}

	public unbind(property: string): void {
		const bindings = this.bindings;
		if (!bindings) {
			return;
		}

		const binding = bindings.get(property);
		if (binding) {
			binding.unbind();
			bindings.delete(property);
			if (binding.sourceIsBindingContext) {
				if (property === 'bindingContext') {
					this.shouldAddHandlerToParentBindingContextChanged = false;
					this.bindingContextBoundToParentBindingContextChanged = false;
					const parent = this.parent;
					if (parent) {
						parent.off('bindingContextChange', this.bindingContextChanged, this);
					}
				}
			}
		}
	}

	private performLayout(currentRun = 0) {
		// if there's an animation in progress we need to delay the layout
		// we've added a guard of 5000 milliseconds execution