找回密码
 加入
搜索
查看: 3591|回复: 3

[效率算法] eval 和 assign 内部是怎么处理的,有人知道么

  [复制链接]
发表于 2012-9-17 23:25:33 | 显示全部楼层 |阅读模式
我自己也写了个简单的哈希函数,但是和用eval、assgin比起来速度慢了N个等级。
可惜eval和assign本身也有缺陷,还要避免和源代码里自定义的变量重名,还有访问范围等等用的不太爽的地方

有人知道eval和assign内部是怎么处理数据的么?
发表于 2012-9-20 17:31:31 | 显示全部楼层
除了AU3的作者,我想没人能知道两个函数的实现细节。至于变量名称重复的问题,可以使用Random函数给你要定义的变量名加一个随机前缀。
发表于 2012-9-20 17:58:33 | 显示全部楼层
懂VC的话,自己看下吧。
///////////////////////////////////////////////////////////////////////////////
// Eval()
///////////////////////////////////////////////////////////////////////////////

AUT_RESULT AutoIt_Script::F_Eval(VectorVariant &vParams, Variant &vResult)
{
        bool        bConst = false;

         if (g_oVarTable.isDeclared(vParams[0].szValue()))
         {
                 Variant *pvTemp;
                 g_oVarTable.GetRef(vParams[0].szValue(), &pvTemp, bConst);
                 vResult = *pvTemp;
                 return AUT_OK;
         }
         else
         {
                 SetFuncErrorCode(1);                        // Silent error even though variable not valid
                 vResult = "";
                 return AUT_OK;
         }

} // Eval()


//////////////////////////////////////////////////////////////////////////
// F_Assign("variable", "data")
//
// Assign( "varname", "value" [,flag])
//
// binary flag: 0=any, 1=local, 2=global, 4=no create
//
// Assigns the variable in the first parameter to the data in the second parameter.
// This is a compliment to Eval()
//////////////////////////////////////////////////////////////////////////

AUT_RESULT AutoIt_Script::F_Assign(VectorVariant &vParams, Variant &vResult)
{
        Variant *pvTemp;
        int                nReqScope = VARTABLE_ANY;
        bool        bCreate = true;
        bool        bConst = false;

        if (vParams.size() == 3)
        {
                if (vParams[2].nValue() & 1)
                        nReqScope = VARTABLE_FORCELOCAL;
                if (vParams[2].nValue() & 2)
                        nReqScope = VARTABLE_FORCEGLOBAL;
                if (vParams[2].nValue() & 4)
                        bCreate = false;
        }

        // Get a reference to the variable in the requested scope, if it doesn't exist, then create it.
        g_oVarTable.GetRef(vParams[0].szValue(), &pvTemp, bConst, nReqScope);
        if (pvTemp == NULL)
        {
                if (bCreate)
                        g_oVarTable.Assign(vParams[0].szValue(), vParams[1], false, nReqScope);
                else
                        vResult = 0;                                                // Default is 1
        }
        else
                *pvTemp = vParams[1];

        return AUT_OK;

}        // F_Assign()
发表于 2012-9-20 22:17:08 | 显示全部楼层
回复 3# sanhen
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-5 12:43 , Processed in 0.081994 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表