<commit_before>﻿using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using NiL.JS.Core;

namespace NiL.JS.Expressions
{
#if !(PORTABLE || NETCORE)
    [Serializable]
#endif
    public sealed class SetProperty : Expression
    {
        private JSValue _propertyNameTempContainer;
        private JSValue _sourceTempContainer;
        private JSValue _cachedMemberName;
        private Expression _value;

        public Expression Source => _left;
        public Expression FieldName => _right;
        public Expression Value => _value;

        protected internal override bool ContextIndependent => false;

        internal override bool ResultInTempContainer => true;

        internal SetProperty(Expression obj, Expression fieldName, Expression value)
            : base(obj, fieldName, true)
        {
            if (fieldName is Constant)
                _cachedMemberName = fieldName.Evaluate(null);
            else
                _propertyNameTempContainer = new JSValue();
            _value = value;
            _sourceTempContainer = new JSValue();
        }

        public override JSValue Evaluate(Context context)
        {
            lock (this)
            {
                JSValue sjso = null;
                JSValue source = null;
                
                var tc = _tempContainer;
                var pntc = _propertyNameTempContainer;
                var stc = _sourceTempContainer;

                try
                {
                    source = _left.Evaluate(context);
                    if (source._valueType >= JSValueType.Object
                        && source._oValue != null
                        && source._oValue != source
                        && (sjso = source._oValue as JSValue) != null
                        && sjso._valueType >= JSValueType.Object)
                    {
                        source = sjso;
                    }
                    else
                    {
                        if (_sourceTempContainer == null)
                            _sourceTempContainer = new JSValue();

                        _sourceTempContainer.Assign(source);
                        source = _sourceTempContainer;
                        _sourceTempContainer = null;
                    }

                    if (_propertyNameTempContainer == null)
                        _propertyNameTempContainer = new JSValue();
                    var propertyName = _cachedMemberName ?? safeGet(_propertyNameTempContainer, _right, context);
                    _propertyNameTempContainer = null;

                    if (_tempContainer == null)
                        _tempContainer = new JSValue();
                    var value = safeGet(_tempContainer, _value, context);
                    _tempContainer = null;

                    source.SetProperty(
                        propertyName,<commit_msg>Small optimize after fix of #196<commit_after>﻿using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using NiL.JS.Core;

namespace NiL.JS.Expressions
{
#if !(PORTABLE || NETCORE)
    [Serializable]
#endif
    public sealed class SetProperty : Expression
    {
        private JSValue _propertyNameTempContainer;
        private JSValue _sourceTempContainer;
        private JSValue _cachedMemberName;
        private Expression _value;

        public Expression Source => _left;
        public Expression FieldName => _right;
        public Expression Value => _value;

        protected internal override bool ContextIndependent => false;

        internal override bool ResultInTempContainer => true;

        internal SetProperty(Expression obj, Expression fieldName, Expression value)
            : base(obj, fieldName, true)
        {
            if (fieldName is Constant)
                _cachedMemberName = fieldName.Evaluate(null);
            else
                _propertyNameTempContainer = new JSValue();
            _value = value;
            _sourceTempContainer = new JSValue();
        }

        public override JSValue Evaluate(Context context)
        {
            lock (this)
            {
                JSValue sjso = null;
                JSValue source = null;
                
                var tc = _tempContainer;
                var pntc = _propertyNameTempContainer;
                var stc = _sourceTempContainer;

                try
                {
                    source = _left.Evaluate(context);
                    if (source._valueType >= JSValueType.Object
                        && source._oValue != null
                        && source._oValue != source
                        && (sjso = source._oValue as JSValue) != null
                        && sjso._valueType >= JSValueType.Object)
                    {
                        source = sjso;
                    }
                    else
                    {
                        if (_sourceTempContainer == null)
                            _sourceTempContainer = new JSValue();

                        _sourceTempContainer.Assign(source);
                        source = _sourceTempContainer;
                        _sourceTempContainer = null;
                    }

                    var propertyName = _cachedMemberName;
                    if (propertyName == null)
                    {
                        if (_propertyNameTempContainer == null)
                            _propertyNameTempContainer = new JSValue();
                        propertyName = safeGet(_propertyNameTempContainer, _right, context);
                        _propertyNameTempContainer = null;
                    }

                    if (_tempContainer == null)
                        _tempContainer = new JSValue();
                    var value = safeGet(_tempContainer, _value, context);
                    _tempContainer = null;

                    source.SetProperty(
                        propertyName,
{'fraction_non_alphanumeric': 0.0635266510224606, 'fraction_numerical': 0.0005028494803888703, 'mean_word_length': 1.3612979817965967, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '2865721', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1239, 'n_words': 332}