问题列表 - 第42265页

为什么我的正则表达式比编译时编译得慢得多?

我有一个庞大而复杂的C#正则表达式,在解释时运行正常,但有点慢.我试图通过设置加快速度RegexOptions.Compiled,这似乎是第一次约30秒,之后立即.我试图通过首先将正则表达式编译为程序集来否定这一点,所以我的应用程序可以尽可能快.

我的问题是编译延迟发生时,是否在应用程序中编译:

Regex myComplexRegex = new Regex(regexText, RegexOptions.Compiled);
MatchCollection matches = myComplexRegex.Matches(searchText);
foreach (Match match in matches) // <--- when the one-time long delay kicks in
{

} 
Run Code Online (Sandbox Code Playgroud)

或提前使用Regex.CompileToAssembly:

MatchCollection matches = new CompiledAssembly.ComplexRegex().Matches(searchText);
foreach (Match match in matches) // <--- when the one-time long delay kicks in
{

} 
Run Code Online (Sandbox Code Playgroud)

这使得编译程序基本没用,因为我仍然在第一次foreach调用时遇到延迟.我想要的是所有的编译延迟都是在编译时完成的(在Regex.CompileToAssembly调用中),而不是在运行时.我哪里错了?

(我用来编译成程序集的代码类似于 http://www.dijksterhuis.org/regular-expressions-advanced/,如果相关的话).

编辑:

new在调用编译的程序集时我应该使用new CompiledAssembly.ComplexRegex().Matches(searchText);吗?但它没有提供"需要对象引用"错误.

更新2

谢谢你的回答/评论.我正在使用的正则表达式很长但基本上很简单,列出了数千个单词,每个单词用|分隔.我真的看不出这是一个回溯问题.主题字符串可以只有一个字母长,它仍然可以导致编译延迟.对于RegexOptions.Compiled正则表达式,当正则表达式包含5000个单词时,执行将需要10秒以上.为了比较,正则表达式的非编译版本可以使用30,000多个单词,并且仍然可以立即执行.

在对此进行了大量测试后,我认为我发现的是:

  • 当你的正则表达式有很多选择时,不要使用RegexOptions.Compiled - 它的编译速度可能非常慢.
  • .Net会在可能的情况下对正则表达式使用惰性求值,AFAI也可以看到这也扩展(至少在某种程度上)到正则表达式编译.正则表达式只有在必要时才会完全编译,并且似乎无法提前强制编译.
  • 如果可以强制完全编译正则表达式,Regex.CompileToAssembly会更有用,它似乎正在接近无意义.

如果我错了或遗漏了什么,请纠正我!

c# regex performance

19
推荐指数
2
解决办法
9248
查看次数

cocos2d中的ccfollow操作

ccfollow动作正确地跟随我的射弹.什么时候,双击识别.

看下面的代码.是错的.

这是我的代码: -

- (void)update:(ccTime)dt {
    if (numTaps==1 ) {
[self runAction:[CCFollow actionWithTarget:nextProjectile worldBoundary:CGRectMake(0,0,1050,350)]];
            }
}

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    numTaps = [[touches anyObject] tapCount];
 printf("Tapcount : %d",numTaps);
    if (numTaps ==1) {

    nextProjectile = [[CCSprite spriteWithFile:@"Weapon.png"] retain];
    nextProjectile.position =  ccp(nextprojectile .contentSize.width/2+65, nextprojectile.contentSize.height/2+70);
[nextProjectile runAction:[CCSequence actions: [here's my nextprojectile actions],nil]];
}
}
Run Code Online (Sandbox Code Playgroud)

看过上面的代码.你提出的一个问题.为什么在if条件中提到ccfollow动作.

答案在这里,通常,我在更新功能中提及它将无法正常工作,当我设置此条件时,如果条件在双击识别后工作.

如何纠正这个问题?

任何帮助将受到高度赞赏.

iphone tap cocos2d-iphone

1
推荐指数
1
解决办法
3247
查看次数

如何在网页上创建两列?

我想在我的网页上有两列.对我来说,简单的方法是使用表格:

<table>
   <tr>
      <td>
         Content of the first column.
      </td>
      <td>
         Content of the second column.
      </td>
   </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

我喜欢这个解决方案,因为,首先,它可以工作(它提供我想要的东西),它也非常简单和稳定(无论我的窗口有多大,我都会有两列.)很容易控制桌子的大小和位置.

但是,我知道人们不喜欢表格布局,据我所知,他们使用div和css代替.所以,我也想尝试这种方法.任何人都可以帮助我吗?

我想有一个易于记忆的简单解决方案(没有技巧).它也需要是稳定的(因此不会意外地发生一列在另一列之下或它们重叠或类似的情况).

html css html-table

14
推荐指数
1
解决办法
14万
查看次数

如何在dev express中的布局视图(网格控件)中添加按钮

HII,

任何人都可以请回答如何在开发快递布局视图中添加按钮.

c# devexpress

2
推荐指数
1
解决办法
5198
查看次数

在java中的子域之间共享Cookie?

问候所有我有一些存储在http://sub1.myserver.com的 cookie ,我希望能够在http://myserver.com上看到它们的 任何想法如何做到这一点?

java cookies java-ee

7
推荐指数
2
解决办法
1万
查看次数

Hibernate JPA2.0和Maven

我尝试构建简单的应用程序,我想使用spring,wicket和JPA2.0(Hibernate).把所有这些放在一起我使用maven.我有hibernate的问题.下面是我的pom.xml

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>comicsTest</groupId>
  <artifactId>comicsTest</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <repositories>
    <repository>
     <id>jboss-public-repository-group</id>
    <name>JBoss Public Repository Group</name>
    <url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
    </repository>
  </repositories>


  <dependencies>
   <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>3.0.5.RELEASE</version>
    <exclusions>
     <exclusion>
      <artifactId>commons-logging</artifactId>
      <groupId>commons-logging</groupId>
     </exclusion>
    </exclusions>
   </dependency>
   <dependency>
    <groupId>wicket</groupId>
    <artifactId>wicket</artifactId>
    <version>1.2.7</version>
   </dependency>
   <dependency>
    <groupId>wicket</groupId>
    <artifactId>wicket-spring</artifactId>
    <version>1.2.7</version>
   </dependency>
   <dependency>
    <groupId>wicket</groupId>
    <artifactId>wicket-extensions</artifactId>
    <version>1.2.7</version>
   </dependency>
   <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>3.0.5.RELEASE</version>
   </dependency>
   <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>3.0.5.RELEASE</version>
   </dependency>
   <dependency>
    <groupId>org.hiberante</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>3.6.0.Final</version>
   </dependency>
  </dependencies>
  <modules>
  </modules>
  <properties>
   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
</project>
Run Code Online (Sandbox Code Playgroud)

而我得到的只是

27.12.10 12:41:44 CET: Refreshing [/comicsTest/pom.xml]
27.12.10 12:41:48 CET: Downloaded …
Run Code Online (Sandbox Code Playgroud)

hibernate maven jpa-2.0

0
推荐指数
1
解决办法
3558
查看次数

我有一个Directory.delete函数的问题?

看看我的代码:

string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        try
        {
            if (Directory.Exists(Path.Combine(desktopPath, "Hackers.avi")))
                Directory.Delete(Path.Combine(desktopPath, "Hackers.avi"), true);
Run Code Online (Sandbox Code Playgroud)

运行文件后我的桌面上仍然存在,为什么?

c#

-1
推荐指数
1
解决办法
113
查看次数

ruby soft delete_if方法?

当我在ruby中有一个数组时,我可以在其上运行一个delete_if块.问题是它从我的数组中删除了元素.我想要相同的功能,除了不对原始数组进行更改,而是返回一个删除了对象的新数组.

例如:

myarr = ["foo", 5, 7, "bar"]
newarr = myarr.delete_if { |e| e.is_a?(String) }
Run Code Online (Sandbox Code Playgroud)

会返回[5,7] newarr,但也会修改原始数组,myarr.

我基本上寻找的是

myarr = ["foo", 5, 7, "bar"]
newarr = myarr.soft_delete_if { |e| e.is_a?(String) }
Run Code Online (Sandbox Code Playgroud)

所以newarr它将具有值[5,7],但myarr仍然具有相同的值.

这样的事情存在吗?非常感谢!

ruby ruby-on-rails

2
推荐指数
1
解决办法
909
查看次数

IzPack替换文本文件中的变量

我试图找出如何在文本文件中使用IzPack替换变量.看起来它应该是一件简单的事情,但我找不到使用现有文档执行此操作的具体示例.

有任何想法吗?

提前致谢.

java installer izpack

3
推荐指数
1
解决办法
4521
查看次数

如何调用C#DLL的函数来接受来自C#的stringstream类型的参数?

我想导入一个非托管C++ DLL并调用一个stringstream作为参数的函数.在C#中,没有stringstream类,所以有人能告诉我如何从C#程序调用这样的函数吗?

c# c++ dll visual-c++

8
推荐指数
2
解决办法
1993
查看次数