Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9
This is the forum to discuss the Wrox book Professional ASP.NET 3.5: In C# and VB by Bill Evjen, Scott Hanselman, Devin Rader; ISBN: 9780470187579
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 20th, 2011, 09:19 AM
Registered User
Join Date: Apr 2011
Location: Turnhout, Belgium
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Including NameTable Optimization (page 513)


I don't know much about ASP.NET (yet), but I do know about polymorphism...
The code in listing 10-7 (and subsequent listings where the same technique is used), are not using the atomized strings...

From listing 10-7:

NameTable nt = new NameTable();
object book = nt.Add( "book" );
if ( ... && book.Equals( reader.LocalName ) )
The Add() method returns a string. So, the book variable, even though it's of type object, references a string object.
Since string overrides the Equals() method, the comparison will actually be a string comparison, and not an object reference comparison, as was intended. Polymorphism will cause the string override of Equals() to be called.

What the code should be in order to optimize it with the use of atomized strings is:
if ( ... && ReferenceEquals( book, reader.LocalName ) )
ReferenceEquals() is implemented by System.Object and compares the object references. book is a reference to the atomized string, so it will actually be compared to the atomized Reader.LocalName object reference.


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python code optimization icopec Python 2 December 13th, 2011 05:13 AM
A little optimization puzzle williamlove Pro VB 6 2 October 18th, 2009 02:17 AM
Optimization akkad C# 5 November 1st, 2006 05:27 AM
Optimization of ASP page with VBScript anandham VBScript 0 April 18th, 2005 05:03 AM
Query optimization SubodhKumar SQL Language 1 October 22nd, 2003 06:35 AM

All times are GMT -4. The time now is 08:46 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.